获取文本转语音 (TTS) 的可用区域设置
我正在研究抽认卡程序的文本转语音实现。应读出不同语言的文本。为了正确执行此操作,用户必须选择要阅读的文本的语言(毫无疑问将被存储并稍后使用)。
是否有可能在 Android 系统上获取可用的 TTS 语言?如果没有,是否有可能获取系统上所有可用的区域设置?
我想,我明白了: getAvailableLocales()
和 tts.isLocaleAvailable(locale)
I'm working on a text-to-speech implementation of a flashcard program. Text in different languages should be read out. In order to do this properly the user has to select the language of the text to read (will be stored and used later without question).
Is there a possibility of getting the available TTS languages on an Android system? If not, is there a possibility of getting all availably locales on the system?
I guess, I got it: getAvailableLocales()
and tts.isLocaleAvailable(locale)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
其他人已经完成了艰苦的工作,位于 http://kaviddiss.com/2012/ 08/12/android-text-to-speech-languages/
为了节省您的时间,这里是他们的代码摘录
结果取决于选择的 TTS 引擎。例如,我的一部手机同时包含 Pico-TTS 和 Google 文本转语音引擎。
Q-Smart(越南手机,选择 Google TTS 作为引擎)
并选择 Pico
注意:
TTS 设置 UI 中未列出葡萄牙语。当我在应用程序中以编程方式选择葡萄牙语时,它会带有葡萄牙口音! FWIW 这是我选择葡萄牙语的代码(它接受巴西和葡萄牙语言环境)。
Someone else has done the hard work, at http://kaviddiss.com/2012/08/12/android-text-to-speech-languages/
To save you time, here's their code extract
The results depend on which TTS engine has been selected. For instance, one of my phones includes both the Pico-TTS and Google-text-to-speech engines.
Q-Smart (Vietnamese Phone with Google TTS as selected engine)
And with Pico selected
Note:
Portuguese isn’t listed in the TTS Settings UI. When I select Portuguese programmatically in my app it speaks with a Portuguese accent! FWIW here's my code to select Portuguese (it accepts both Brazilian and Portuguese locales).
由于不同的 TTS 引擎返回的
isLanguageAvailable
结果不同,我发现以下解决方案在几种常见的 TTS 引擎上效果最佳。另请注意,从 Android Lollipop 开始,
TextToSpeech
中有一个简单的方法,名为getAvailableLanguages
可以轻松为您完成此操作(如果设备运行 API 21 或更高版本)。您需要在分配给
TextToSpeech
对象的OnInitListener
的onInit
方法中调用以下方法。Since different TTS engines return different results for
isLanguageAvailable
, I found that the following solution works best on several common TTS engines.Please also note that starting with Android Lollipop, there is a simple method in
TextToSpeech
calledgetAvailableLanguages
that does that easily for you (if the device is running API 21 or later).You need to call the following methods in the
onInit
method of yourOnInitListener
assigned to theTextToSpeech
object.使用以下函数查找设备上所有可用的 TTS 区域设置。
输出: Arrays.toString(Locale.getAvailableLocales())
Find all available TTS Locale on the device using following function.
Output of: Arrays.toString(Locale.getAvailableLocales())
从 Android 5.0(API 级别 21)开始,添加了
TextToSpeech.getAvailableLanguages
以获取 TTS 引擎支持的所有区域设置集。我还注意到,
TextToSpeech.getAvailableLanguages
返回的区域设置可能不是Locale.getAvailableLocales
的严格子集,即 TTS 引擎可能支持一个区域设置系统不支持。Starting from Android 5.0 (API level 21),
TextToSpeech.getAvailableLanguages
has been added to fetch a set of all locales supported by the TTS engine.I have also noticed that the set of locales returned by
TextToSpeech.getAvailableLanguages
might not be a strict subset ofLocale.getAvailableLocales
, i.e. there might a locale supported by the TTS engine that isn't supported by the system.