gpt4 book ai didi

android - 获取文本到语音 (TTS) 的可用区域设置

转载 作者:IT老高 更新时间:2023-10-28 23:18:16 24 4
gpt4 key购买 nike

我正在开发一个抽认卡程序的文本到语音转换。应读出不同语言的文本。为了正确执行此操作,用户必须选择要阅读的文本语言(将被存储并在以后毫无疑问地使用)。

是否有可能在 Android 系统上获取可用的 TTS 语言?如果没有,是否有可能获取系统上所有可用的语言环境?


我猜,我明白了:getAvailableLocales()tts.isLocaleAvailable(locale)

最佳答案

其他人已经完成了艰苦的工作,在 http://kaviddiss.com/2012/08/12/android-text-to-speech-languages/

为了节省您的时间,这是他们的代码摘录

TextToSpeech tts = ...
// let's assume tts is already inited at this point:
Locale[] locales = Locale.getAvailableLocales();
List<Locale> localeList = new ArrayList<Locale>();
for (Locale locale : locales) {
int res = tts.isLanguageAvailable(locale);
if (res == TextToSpeech.LANG_COUNTRY_AVAILABLE) {
localeList.add(locale);
}
}
// at this point the localeList object will contain
// all available languages for Text to Speech

结果取决于选择的 TTS 引擎。例如,我的一部手机同时包含 Pico-TTS 和 Google-text-to-speech 引擎。

Q-Smart(以 Google TTS 作为选定引擎的越南手机)

D/SpeakRepeatedly( 3979): Engine Google Text-to-speech Engine:com.google.android.tts
D/SpeakRepeatedly( 3979): Engine Pico TTS:com.svox.pico
D/SpeakRepeatedly( 3979): German (Germany):German:de_DE
D/SpeakRepeatedly( 3979): English (United Kingdom):English:en_GB
D/SpeakRepeatedly( 3979): English (United States):English:en_US
D/SpeakRepeatedly( 3979): English (United States,Computer):English:en_US_POSIX
D/SpeakRepeatedly( 3979): Spanish (Spain):Spanish:es_ES
D/SpeakRepeatedly( 3979): French (France):French:fr_FR
D/SpeakRepeatedly( 3979): Italian (Italy):Italian:it_IT
D/SpeakRepeatedly( 3979): Portuguese (Brazil):Portuguese:pt_BR
D/SpeakRepeatedly( 3979): Portuguese (Portugal):Portuguese:pt_PT

并且选择了 Pico

D/SpeakRepeatedly( 4837): Engine Google Text-to-speech Engine:com.google.android.tts
D/SpeakRepeatedly( 4837): Engine Pico TTS:com.svox.pico
D/SpeakRepeatedly( 4837): German (Germany):German:de_DE
D/SpeakRepeatedly( 4837): English (United Kingdom):English:en_GB
D/SpeakRepeatedly( 4837): English (United States):English:en_US
D/SpeakRepeatedly( 4837): English (United States,Computer):English:en_US_POSIX
D/SpeakRepeatedly( 4837): Spanish (Spain):Spanish:es_ES
D/SpeakRepeatedly( 4837): French (France):French:fr_FR
D/SpeakRepeatedly( 4837): Italian (Italy):Italian:it_IT

注意:葡萄牙语未在 TTS 设置 UI 中列出。当我在我的应用程序中以编程方式选择葡萄牙语时,它会说葡萄牙口音! FWIW 这是我选择葡萄牙语的代码(它同时接受巴西和葡萄牙语区域​​设置)。

if (locale.getDisplayName().startsWith("Portuguese")) {
Log.i(SPEAK_REPEATEDLY, "Setting Locale to: " + locale.toString());
tts.setLanguage(locale);
}
}

关于android - 获取文本到语音 (TTS) 的可用区域设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4872702/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com