@@ -25,30 +25,33 @@ export class TNSTextToSpeech {
2525
2626 private async init ( ) {
2727 if ( ! this . _tts || ! this . _initialized ) {
28- this . _tts = new android . speech . tts . TextToSpeech (
29- this . _getContext ( ) ,
30- new android . speech . tts . TextToSpeech . OnInitListener ( {
31- onInit : ( status ) => {
32- // if the TextToSpeech was successful initializing
33- if ( status === android . speech . tts . TextToSpeech . SUCCESS ) {
34- this . _initialized = true ;
35- const listener = new UtteranceProgressListener ( ) ;
36- this . listener = listener ;
37- this . _tts . setOnUtteranceProgressListener ( listener ) ;
38- } else {
39- throw new Error ( 'TextToSpeech failed to init with code ' + status ) ;
40- }
41- } ,
42- } )
43- ) ;
28+ return new Promise < void > ( ( resolve , reject ) => {
29+ this . _tts = new android . speech . tts . TextToSpeech (
30+ this . _getContext ( ) ,
31+ new android . speech . tts . TextToSpeech . OnInitListener ( {
32+ onInit : ( status ) => {
33+ // if the TextToSpeech was successful initializing
34+ console . log ( 'init done' , status ) ;
35+ if ( status === android . speech . tts . TextToSpeech . SUCCESS ) {
36+ this . _initialized = true ;
37+ const listener = new UtteranceProgressListener ( ) ;
38+ this . listener = listener ;
39+ this . _tts . setOnUtteranceProgressListener ( listener ) ;
40+ resolve ( ) ;
41+ } else {
42+ reject ( new Error ( 'TextToSpeech failed to init with code ' + status ) ) ;
43+ }
44+ } ,
45+ } )
46+ ) ;
47+ } ) ;
4448 }
4549 }
4650
4751 public async speak ( options : SpeakOptions ) {
4852 if ( ! this . isString ( options . text ) ) {
4953 throw new Error ( 'Text property is required to speak.' ) ;
5054 }
51-
5255 await this . init ( ) ;
5356 let maxLen : number = 4000 ; // API level 18 added method for getting value dynamically
5457 if ( android . os . Build . VERSION . SDK_INT >= 18 ) {
@@ -148,7 +151,7 @@ export class TNSTextToSpeech {
148151 this . _tts . setSpeechRate ( options . speakRate ) ;
149152
150153 const queueMode = options . queue ? android . speech . tts . TextToSpeech . QUEUE_ADD : android . speech . tts . TextToSpeech . QUEUE_FLUSH ;
151-
154+ console . log ( 'about to speak' ) ;
152155 if ( android . os . Build . VERSION . SDK_INT >= 21 ) {
153156 // Hardcoded this value since the static field LOLLIPOP doesn't exist in Android 4.4
154157 /// >= Android API 21 - https://developer.android.com/reference/android/speech/tts/TextToSpeech.html#speak(java.lang.CharSequence, int, android.os.Bundle, java.lang.String)
0 commit comments