2

我尝试JAPANESE在我的 Android 4 设备上使用语言。

int value = tts.setLanguage(Locale.JAPANESE);

但值为-2。

这是我的检查代码

protected void check(int requestCode, int resultCode, Intent data) {
        if (requestCode == 0) {
            switch (resultCode) {
            case TextToSpeech.Engine.CHECK_VOICE_DATA_PASS:
                tts = new TextToSpeech(this, this);
                break;
            case TextToSpeech.Engine.CHECK_VOICE_DATA_BAD_DATA:
            case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_DATA:
            case TextToSpeech.Engine.CHECK_VOICE_DATA_MISSING_VOLUME:
                Intent installIntent = new Intent();
                installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
                startActivity(installIntent);
                break;
            case TextToSpeech.Engine.CHECK_VOICE_DATA_FAIL:
            default:
                Log.e(TAG, "Got a failure. TTS not available");
            }
        }
    }

如果不存在,我想安装语言。但应用程序崩溃。这是正确的,我该怎么办?如何获得日语?

4

1 回答 1

2

You start your method by testing result code is equal to 0 and then have a swith on result code value (which you already know is equal to 0):

    if (requestCode == 0) {
        switch (resultCode) {

As written in your code, if language is not installed tts will not be initialized and any further reference to it will crash you application.

You can see the correct way to do it in An introduction to Text-To-Speech in Android

Regards.

于 2012-11-15T15:31:03.967 回答