问题描述
管理,使TextToSpeech.setEngineByPackageName()工作的感谢之后,我现在具有反其道而行之问题:
After managing to make TextToSpeech.setEngineByPackageName() work thanks to this answer, I am now having the "opposite" problem:
tts.setEngineByPackageName(com.ivona.tts.voicebeta.eng.usa.kendra);
总是返回 TextToSpeech.SUCCESS 即使当该包未在所有已安装在设备中。
tts.setEngineByPackageName("com.ivona.tts.voicebeta.eng.usa.kendra");
always returns TextToSpeech.SUCCESS, even when that package is not installed at all in the device.
由于包不可用在设备上,TTS继续与Android的默认微微
,预计说话,但我不明白为什么 setEngineByPackageName()
返回SUCCESS。
Since the package is not available on the device, TTS proceeds to speak with Android's default pico
, which is expected, but I don't understand why setEngineByPackageName()
returns SUCCESS.
怎么会这样?
推荐答案
有关的所有,我张贴由的:
For the benefit of all, I am posting the answer provided by @Nikolay Elenkov on a different (but related) question:
调用setEngineByPackageName()时,包不存在是不是一个好主意。相反,检查它是否已安装和不要尝试使用它,如果它没有安装
Calling setEngineByPackageName() when the package doesn't exists is not a good idea. Instead, check if it is installed and don't try to use it if it's not installed:
boolean isPackageInstalled(String packageName) {
PackageManager pm = context.getPackageManager();
try {
PackageInfo pi = pm.getPackageInfo(packageName, 0);
return pi != null;
} catch (NameNotFoundException e) {
return false;
}
}
这是如何实现的一个很好的例子可以看出:
A good example of how this is done can be seen at:
<一个href=\"http://$c$c.google.com/p/wwwjdic/source/browse/branches/2.0/wwwjdic/src/org/nick/wwwjdic/TtsManager.java\" rel=\"nofollow\">http://$c$c.google.com/p/wwwjdic/source/browse/branches/2.0/wwwjdic/src/org/nick/wwwjdic/TtsManager.java
这篇关于即使没有可用的package TextToSpeech.setEngineByPackageName()返回成功信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!