cordova-plugin-tts
cordova-plugin-tts copied to clipboard
speak() fails with ERR_NOT_INITIALIZED
Issue
I'm getting ERR_NOT_INITIALIZED
when using tts.speak()
.
Scenario
I'm using this plugin on Ionic 3 and after build and deploying on a phone (not a emulator) it always fail, I mean, it goes through the catch()
of it's promise providing ERR_NOT_INITIALIZED
as reason.
My code look like this:
this.tts.speak({
locale: 'en-GB',
rate: 0.75,
text: message
}).then(() => {
console.log('Success');
}).catch((reason: any) => {
console.error('Error', reason);
});
I even tried using the developer tools of chrome to access my phone and tried a code I found on the internet that looks like the next one and it's the same:
TTS.speak('hello', function(data) {
console.log('OK' ,data);
}, function(data) {
console.log('FAILED', data);
})
And it showed this:
FAILED ERR_NOT_INITIALIZED
My info
I used this page to know how to use this plugin:
- https://ionicframework.com/docs/native/text-to-speech/
My ionic info
shows this:
cli packages: (...../node_modules)
@ionic/cli-utils : 1.9.2
ionic (Ionic CLI) : 3.9.2
global packages:
Cordova CLI : 7.0.1
local packages:
@ionic/app-scripts : 2.1.4
Cordova Platforms : android 6.2.3
Ionic Framework : ionic-angular 3.6.0
System:
Android SDK Tools : 26.0.2
Node : v6.11.1
npm : 3.10.10
OS : Linux 4.8
My ionic cordova plugin
shows this:
cordova-plugin-console 1.0.7 "Console"
cordova-plugin-device 1.1.6 "Device"
cordova-plugin-speechrecognition 1.1.2 "Speech Recognition"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.3 "StatusBar"
cordova-plugin-tts 0.2.3 "TTS"
cordova-plugin-whitelist 1.3.2 "Whitelist"
ionic-plugin-keyboard 2.2.1 "Keyboard"
Hi, I had the same issue, but my configuration was different (Cordova + javascript). This is how I fixed it : I searched in the java file when the issue was raising. myApp\plugins\cordova-plugin-tts\src\android\TTS.java
It's happening here, in the function : private void speak(...)
if (!ttsInitialized) {
callbackContext.error(ERR_NOT_INITIALIZED);
And ttsInitialized is declared true in
@Override
public void onInit(int status) {
if (status != TextToSpeech.SUCCESS) {
tts = null;
} else {
// warm up the tts engine with an empty string
HashMap<String, String> ttsParams = new HashMap<String, String>();
ttsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "");
tts.setLanguage(new Locale("en", "US"));
tts.speak("", TextToSpeech.QUEUE_FLUSH, ttsParams);
ttsInitialized = true;
}
}
So the problem appears to be ; status != TextToSpeech.SUCCESS I installed the google tts in my phone. Then it worked.
Same issue here, using devapp, I succeed with the audio playing many times, after no modification to the service, it's now throwing that error for no reason.
If it's something related with devapp or initialization, please provide race conditions or init procedures.
Thanks, Best
fiy, after some reboots it now works