自动下载android TTS引擎 [英] Automatically download android TTS engine

查看:115
本文介绍了自动下载android TTS引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have developed an app based on TTS for Android 2.3. I am noticing that in recent version of Android (4.2.2) for example, no default TTS language where installed by default, you have to manually download them by going into: Settings --> Language and input --> Text to speech output --> Google Text-To-speech --> Install voice data

有没有一种自动安装语言的方法?

Is there a way to install a language automatically?

推荐答案

是否可以自动安装语言?

Is there a way to install a language automatically?

是的,但是不会自动发生(未经用户同意),如

Yes, but that will not happen automatically (without user consent) as mentioned in the 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...

无论如何,您可以使用

Anyhow, you can trigger the installation with something like 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 TTS引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆