安卓,文本转语音
我正在尝试文本转语音,以使我的测试应用程序更有趣。它可以在模拟器中运行,但不能在我的手机上运行,因为我的默认区域设置不是英语。
然而,文本是英文的,所以 tts 当然应该使用英文。据我所知,我可以实现自动安装,例如
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
// Set preferred language to US english.
int result = mtts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA ||
result == TextToSpeech.LANG_NOT_SUPPORTED) {
// Lanuage data is missing or the language is not supported.
Log.e(TAG, "Language is not available.");
} else {
// The TTS engine has been successfully initialized.
speak();
}
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
但是,我想要吗?安装语言环境是否会占用大量空间?它会弄乱其他东西吗?
问候
I'm playing with text to speech to make my testapp a little more fun. It works in the emulator but not on my phone since my default locale isn't english.
However, the texts are english so the tts should of course use english. As far as I know I can implement an autoninstall, something like
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
// Set preferred language to US english.
int result = mtts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA ||
result == TextToSpeech.LANG_NOT_SUPPORTED) {
// Lanuage data is missing or the language is not supported.
Log.e(TAG, "Language is not available.");
} else {
// The TTS engine has been successfully initialized.
speak();
}
} else {
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
But, do I want to? Does installing locales take a lot of space? Does it mess up something else?
regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你应该执行这个:
当你得到 LANG_MISSING_DATA 时
You should execute this:
when you get LANG_MISSING_DATA
我只会在“LANG_MISSING_DATA”不适用于“LANG_NOT_SUPPORTED”的情况下尝试安装。由于它启动另一个活动,并且用户可以选择是否下载它,所以我不会太担心它占用空间。不,它不应该搞乱任何事情。
I would only try the install in the case where "LANG_MISSING_DATA" not for "LANG_NOT_SUPPORTED". Since it starts another activity and the user can choose whether they download it or not, I wouldn't worry too much about it taking space. No, it shouldn't mess anything up.
Android 允许您将文本转换为语音。您不仅可以转换它,还可以让您用各种不同的语言说出文本。
Android 为此提供了 TextToSpeech 类。
有关更多详细信息,请按照本教程操作:-
http://a-droidtech.blogspot.in/2015/06/android-text-to-speech-tutorial-android.html
Android allows you convert your text into voice. Not only you can convert it but it also allows you to speak text in variety of different languages.
Android provides TextToSpeech class for this purpose.
For more detail please follow this tutorial :-
http://a-droidtech.blogspot.in/2015/06/android-text-to-speech-tutorial-android.html