问题描述
我使用的是来自但是插件似乎不工作。
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 does not even initialize.
$ b
安装插件如下(PHONEGAP 3.3)
Installed the plugin like below (PHONEGAP 3.3 )
phonegap plugin add https://github.com/domaemon/org.apache.cordova.plugin.tts.git
phonegap build android
在phonegap config.xml中添加了以下内容
Added the following in the phonegap config.xml
<gap:plugin name="org.apache.cordova.plugins.tts" value="org.apache.cordova.plugins.tts"/>
在我的javascript中添加了以下代码
Added the following code 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 genymotion emulator.
推荐答案
经过一番努力后,我有TTS工作。但还有一个问题,我不得不手动修复。以下是获取TTS工作的步骤
After some struggle i have the TTS working. But there is still one issue i had to manually fix. Following are the steps to get the TTS Working
按如下所示安装插件。
phonegap plugin add https://github.com/domaemon/org.apache.cordova.plugin.tts.git
phonegap build android
一旦安装和构建。将此插件添加到phonegap config.xml文件。 (如果您使用sencha touch构建应用程序,config.xml将位于根文件夹中。)
Once installed and built. Add this plugin to the phonegap config.xml file. ( If you are building the app using sencha touch, the config.xml will be in the root folder. )
<gap:plugin name="org.apache.cordova.plugins.tts" value="org.apache.cordova.plugins.tts"/>
这会将插件添加到最终版本。现在启动TTS服务并讲一些文本,使用以下代码片段。
This will add the plugin to the final build. Now to start the TTS Service and speak 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);
}
我的问题是TTS.STARTED在startupWin中没有定义插件。我只是使用常量的值和插件工作完美。
The issue i had was the TTS.STARTED in the startupWin is not defined in the plugin. I just used the constant's value and the plugin works perfectly.
这篇关于Phonegap TTS插件Android不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!