nativescript-community / texttospeech

Text to Speech NativeScript plugin for Android & iOS :loudspeaker:
http://nativescript-community.github.io/texttospeech/
MIT License
50 stars 24 forks source link

Added some Promises, added support for locales and languages on Android, added 'getAvailableLanguages()' for Android #9

Closed svzi closed 7 years ago

svzi commented 7 years ago

I've modified speak() to return a Promise instead of void. This allows better error handling. I've updated the README.md accordingly and I added myself as contributor, upon your request on Slack. :)

I'm not sure why here are so many changes listed. The husky task did run prior my push:


> husky - npm run -s precommit
> husky - node v6.9.5

 ✔ Running tasks for *.ts
[master 9342011] Modified 'speak()' to return a Promise
 5 files changed, 153 insertions(+), 115 deletions(-)

I hope everything else is ok. Let me know if I did miss something.

svzi commented 7 years ago

I've added another commit and I was forced to introduce a breaking API change.

SpeakOptions.language got renamed to SpeakOptions.locale, because of that is exactly what it was used for. The property did not contain the ISO 639-1 language code (like en), but the BCP-47 code (like en-US).

I needed the ability to instantiate a TTS instance with the language only. For that reason I did the renaming. I've also updated the README.md and provided some samples. All changes are made to not break any existing integrations of the plugin. So the plugin will work withSpeakOptions.language = 'en-US'; as well (like it did before my changes).

I've also added an Android-only method, for querying all available languages of the device: getAvailableLanguages(): Promise<Array<Language>>. That method can really help to prevent using wrong / not-existing language codes or locale codes.

That method could probably be implemented for iOS as well: https://developer.apple.com/documentation/avfoundation/avspeechsynthesisvoice/1619697-speechvoices?language=objc