android - 自动下载android TTS引擎

标签 android text-to-speech

我已经为 Android 2.3 开发了一个基于 TTS 的应用程序。 我注意到,例如,在最新版本的 Android (4.2.2) 中,默认情况下没有安装默认的 TTS 语言,您必须通过以下方式手动下载它们: 设置 --> 语言和输入 --> 文字转语音输出 --> Google 文字转语音 --> 安装语音数据

有没有办法自动安装语言?

最佳答案

Is there a way to install a language automatically?

是的,但这不会自动发生(未经用户同意),如 docs 中所述:

Since the installation of the data can be interrupted or declined by the user, the application shouldn't expect successful installation upon return from that intent...

无论如何,您可以使用类似 this 的方式触发安装:

/**
 * Ask the current default engine to launch the matching INSTALL_TTS_DATA activity
 * so the required TTS files are properly installed.
 */
private void installVoiceData() {
    Intent intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setPackage("com.google.android.tts"/*replace with the package name of the target TTS engine*/);
    try {
        Log.v(TAG, "Installing voice data: " + intent.toUri(0));
        startActivity(intent);
    } catch (ActivityNotFoundException ex) {
        Log.e(TAG, "Failed to install TTS data, no acitivty found for " + intent + ")");
    }
}

关于android - 自动下载android TTS引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16835847/

相关文章:

c# - 使用 Phonics Sounds 的文字转语音

javascript - 使用 speechSynthesis.speak() 在 javascript 中同步执行

android - 文本转语音在 Android 上不工作

android - 路径像水平菜单按钮

Android : canvas. drawoval() + 旋转

android - 将图像大小调整为精确的文件大小

android - 文字转语音 : check if it is on-line or off-line for API < 21

android - 如何在 android 中创建自定义数字选择器?

android - 如何编写Calabash Android的步骤定义

android - 适用于移动平台的文本转语音