我正在研究安卓的TextToSpeech引擎。初始化代码是
TextToSpeech mTTS;
mTTS=new TextToSpeech(this, this, "android.speech.tts");
mTTS.setEngineByPackageName("android.speech.tts");
Intent checkTTSIntent = new Intent();
checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);但这段代码是我手机上的一个选择对话框,用于选择b/w谷歌的TextToSpeech引擎或三星TextToSpeech引擎。现在我要移除这个

选择框并直接加载Google的TTS引擎,无需用户交互。请帮我一把:
发布于 2016-05-30 15:16:27
出于意图(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA),我相信您正在尝试检查TTS数据是否安装在设备上。顺便说一句,这将检查默认的设备语言,如果没有安装,它将给出TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA onActivityResult()的resultCode。
请在下面找到初始化TTS和处理错误的适当方法。
system = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
system.setRecognitionListener(this);
speech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
result = speech.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not available, attempting download");
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
else {
Log.e("TTS", "Initialization Failed!");
}
}
}, "com.google.android.tts");请注意以下3点:
使用这种方法,您将不会获得任何弹出的对话框和tts将被初始化。如果有帮助请告诉我!
https://stackoverflow.com/questions/28416203
复制相似问题