Android phone TTS plugin not working

I am using the TTS plugin from https://github.com/domaemon/org.apache.cordova.plugin.tts But the plugin does not seem to work. It is not even initialized.

Installed the plugin as shown below (PHONEGAP 3.3)

phonegap plugin add https://github.com/domaemon/org.apache.cordova.plugin.tts.git phonegap build android 

Added the following to phonegap config.xml

 <gap:plugin name="org.apache.cordova.plugins.tts" value="org.apache.cordova.plugins.tts"/> 

The following code is added in my javascript

 window.plugins.tts.startup(startupWin, fail); function startupWin(result) { console.log("Startup win"); // When result is equal to STARTED we are ready to play if (result == TTS.STARTED) { window.plugins.tts.getLanguage(win, fail); window.plugins.tts.speak("The text to speech service is ready"); window.plugins.tts.isLanguageAvailable("en_US", function() { addLang("en_US", "English (American)"); }, fail); window.plugins.tts.isLanguageAvailable("en_GB", function() { addLang("en_GB", "English (UK)"); }, fail); window.plugins.tts.isLanguageAvailable("fr", function() { addLang("fr", "French"); }, fail); window.plugins.tts.isLanguageAvailable("de", function() { addLang("de", "German"); }, fail); window.plugins.tts.isLanguageAvailable("it", function() { addLang("it", "Italian"); }, fail); window.plugins.tts.isLanguageAvailable("es", function() { addLang("es", "Spanish"); }, fail); } } function addLang(loc, lang) { var langs = document.getElementById('langs'); var langOption = document.createElement("OPTION") langOption.innerText = lang; langOption.value = loc; langs.options.add(langOption); } function changeLang() { var yourSelect = document.getElementById('langs'); window.plugins.tts.setLanguage(yourSelect.options[yourSelect.selectedIndex].value, win, fail); } function win(result) { console.log(result); } function fail(result) { console.log("Error = " + result); } function speak() { console.log("Speaking"); window.plugins.tts.speak("How are you"); } 

But none of the console log messages are displayed. I am testing this on a genymotion emulator.

+6
source share
2 answers

After some struggle, TTS works for me. But there is another problem that I had to fix manually. Below are the steps required for TTS to work.

Install the plugin as shown below.

 phonegap plugin add https://github.com/domaemon/org.apache.cordova.plugin.tts.git phonegap build android 

After installation and assembly. Add this plugin to the config.xml phonegap file. (If you create the application using sencha touch, config.xml will be in the root folder.)

 <gap:plugin name="org.apache.cordova.plugins.tts" value="org.apache.cordova.plugins.tts"/> 

This will add the plugin to the final build. Now, to start the TTS service and talk with some text, use the following snippet.

 navigator.tts.startup(startupWin, fail); function startupWin(result) { console.log("Startup win"); // When result is equal to STARTED we are ready to play console.log("Result "+result); //TTS.STARTED==2 use this once so is answered if (result == 2) { navigator.tts.getLanguage(win, fail); navigator.tts.speak("The text to speech service is ready"); } } function win(result) { console.log(result); } function fail(result) { console.log("Error = " + result); } 

The problem I had in TTS.STARTED in startupWin is not defined in the plugin. I just used a constant value and the plugin works fine.

+10
source

result == 2 or STARTED only works once. If you call the function again, it may not return 2 or START (happened to me). therefore, it is better not to use this condition on a successful start.

 /*********tts.js*************/ var tts = { say: function() { alert("tts"); }, startup: function(successCallback, errorCallback) { console.log("TTS-Startup"); cordova.exec(successCallback, errorCallback, "TTS", "startup", []); }, speed: function(speed, successCallback, errorCallback) { cordova.exec(successCallback, errorCallback, "TTS", "speed", [speed]); }, speak: function(text, successCallback, errorCallback) { cordova.exec(successCallback, errorCallback, "TTS", "speak", [text]); } }; if(!window.plugins) { window.plugins = {}; } if (!window.plugins.tts) { window.plugins.tts = tts; } /**********calling from your js after device ready***************/ function visitToString(){ window.plugins.tts.startup(function(result){ window.plugins.tts.speed(50,function(){ console.log('speed success'); },function(err){ console.log('speed err'+JSON.stringify(err)); }); window.plugins.tts.speak(finalstr,function(){ console.log('speech success'); },function(err){ console.log('speech err'+JSON.stringify(err)); }); }, fail); } 
 <button id="speakvisit" onclick="visitToString();">Audio Details </button> 
0
source

All Articles