如何在TTS android中设置更多语言?

时间:2012-04-18 06:59:43

标签: android text-to-speech

见下图

enter image description here

enter image description here

请看图片.. 首先我按下单击发言,然后打开单选按钮并选择语言.. 当我选择英语时,必须用英语转换。 我只选择一种语言,然后使用相同的蹩脚语言进行转换。 有可能吗?怎么样?

我会尽快回答它的紧急情况。

由于

1 个答案:

答案 0 :(得分:2)

试试这个

private TextToSpeech mTts;
protected void onActivityResult(
        int requestCode, int resultCode, Intent data) {
    if (requestCode == MY_DATA_CHECK_CODE) {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            // success, create the TTS instance
            mTts = new TextToSpeech(this, this);
        } else {
            // missing data, install it
            Intent installIntent = new Intent();
            installIntent.setAction(
                TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);
        }
    }
}

// 并为语言编写此代码

mTts.setLanguage(Locale.US);
mTts.isLanguageAvailable(Locale.UK))

mTts.isLanguageAvailable(Locale.FRANCE))

mTts.isLanguageAvailable(new Locale("spa", "ESP")))

// 为speack制作文字

String myText1 = "Did you sleep well?";
String myText2 = "I hope so, because it's time to wake up.";
mTts.speak(myText1, TextToSpeech.QUEUE_FLUSH, null);
mTts.speak(myText2, TextToSpeech.QUEUE_ADD, null);