谷歌TTS-Android操作系统中的文本到语音错误

谷歌TTS-Android操作系统中的文本到语音错误,android,Android,我想知道,我真的不知道为什么android中的文本语音转换有时非常顺利,但有时(很少)出现错误,弹出消息Google文本语音引擎已经停止,然后我的设备被卡住,直到弹出窗口出现并关闭,然后我可以继续我的下一个活动 你有另一个代码支持所有android设备的语音引擎(谷歌和三星) 以下是我正在使用的代码: 班级级别: private int MY_DATA_CHECK_CODE = 0; private TextToSpeech tts; private void speakWords(Strin

我想知道,我真的不知道为什么android中的文本语音转换有时非常顺利,但有时(很少)出现错误,弹出消息Google文本语音引擎已经停止,然后我的设备被卡住,直到弹出窗口出现并关闭,然后我可以继续我的下一个活动

你有另一个代码支持所有android设备的语音引擎(谷歌和三星)

以下是我正在使用的代码:

班级级别:

private int MY_DATA_CHECK_CODE = 0;
private TextToSpeech tts;
private void speakWords(String speech) {
    //speak straight away
    tts.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == MY_DATA_CHECK_CODE) {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            //the user has the necessary data - create the TTS
            tts = new TextToSpeech(this, this);
        }
        else {
                //no data - install it now
            Intent installTTSIntent = new Intent();
            installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installTTSIntent);
        }
    }
}
//setup TTS
public void onInit(int initStatus) {
        //check for successful instantiation
    if (initStatus == TextToSpeech.SUCCESS) {
        if(tts.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE)
            tts.setLanguage(Locale.US);
    }
    else if (initStatus == TextToSpeech.ERROR) {
        Toast.makeText(this, "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show();
    }
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}
onCreate级别:

//check for TTS data
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);
按下按钮时:

String speech_question = getResources().getString(R.string.question_1);
speakWords(speech_question);
课后级别:

private int MY_DATA_CHECK_CODE = 0;
private TextToSpeech tts;
private void speakWords(String speech) {
    //speak straight away
    tts.speak(speech, TextToSpeech.QUEUE_FLUSH, null);
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == MY_DATA_CHECK_CODE) {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            //the user has the necessary data - create the TTS
            tts = new TextToSpeech(this, this);
        }
        else {
                //no data - install it now
            Intent installTTSIntent = new Intent();
            installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installTTSIntent);
        }
    }
}
//setup TTS
public void onInit(int initStatus) {
        //check for successful instantiation
    if (initStatus == TextToSpeech.SUCCESS) {
        if(tts.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE)
            tts.setLanguage(Locale.US);
    }
    else if (initStatus == TextToSpeech.ERROR) {
        Toast.makeText(this, "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show();
    }
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}
上面的代码运行得非常好,但有时当我一次又一次尝试刷新活动,并一次又一次按下按钮对文本进行语音处理时,我的三星Galaxy S3给我的错误结果是Google文本语音转换引擎已停止,然后我的设备被卡住,直到弹出窗口出现并关闭,然后我可以继续我的下一个活动

我的问题是,您是否有其他方法来使用支持所有设备的TTS

星系S3中的错误图片如下。

当S3设备上的错误修复时,您可以发布logcat的输出吗?好的,请稍候。。我将在这里打印屏幕并上传。不幸的是,屏幕截图没有帮助。读取您的logcat输出会很有帮助。您可以使用adb:adb logcat从计算机上的命令行获取logcat输出。更多有关logcat的信息,请参见:亲爱的Alex,如果您启动它并使用emulator进行测试,我没有发现TTS有任何错误:(好的,我理解这一点。但是您的设备出现错误。因此,您可以在应用程序崩溃后用电缆将其连接到您的计算机,并像adb logcat一样用adb读取日志,以便您可以获得更具体的错误消息,以确定出了什么问题。