如何检查是否安装了设备上的文本特定的语言数据语音(TTS)? [英] How to check if a specific language data for Text to Speech(TTS) is installed on a device?

查看:713
本文介绍了如何检查是否安装了设备上的文本特定的语言数据语音(TTS)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建它使用文本到语音的应用程序,我希望用户必须使用它的能力下线,所以我做一个检查,看看是否安装在设备上的TTS数据,这里是thde code它做到这一点:

I am creating an app which uses Text to Speech and I want the user to have the ability to use it offline so I make a check to see if the TTS data is installed on the device, here is thde code which does this:

// Check tts data is installed
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);

protected void onActivityResult(int requestCode, int resultCode, Intent data){
    if(requestCode == MY_DATA_CHECK_CODE){
        if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){
            tts = new TextToSpeech(this, this);
        }
        else{
            Intent installTTSIntent = new Intent();
            installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installTTSIntent);
        }
    }
}

但是,这会提示用户安装德语,西班牙语,法语和意大利语四个下载选项,我怎么能才刚刚检查一种语言安装,如意大利?

But this prompts the user to install German, Spanish, French and Italian as four download options, how can I just just check that one language is installed such as Italian?

我做了一些研究,但我在努力寻找code例子这样可以让我实现这一目标。

I have done some research but I am struggling to find code examples which would allow me to achieve this.

推荐答案

使用 EXTRA_CHECK_VOICE_DATA_FOR

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == MY_DATA_CHECK_CODE) {
    if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
        tts = new TextToSpeech(this, this);
    }
    else {
        Intent installTTSIntent = new Intent();
        installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
        ArrayList<String> languages = new ArrayList<String>();
        languages.add("it-IT"); // non sure if "it" is the right abbr for italian
        installTTSIntent.putStringArrayListExtra(TextToSpeech.Engine.EXTRA_CHECK_VOICE_DATA_FOR, 
                                                    languages);
        startActivity(installTTSIntent);
    }
    }
}

文档链接<一个href=\"http://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine.html#EXTRA_CHECK_VOICE_DATA_FOR\" rel=\"nofollow\">http://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine.html#EXTRA_CHECK_VOICE_DATA_FOR

这篇关于如何检查是否安装了设备上的文本特定的语言数据语音(TTS)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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