我想知道如何以编程方式获取设备的TTS引擎信息,例如是否安装了TTS引擎,如果安装了TTS引擎,那么这些引擎是什么,每个TTS引擎支持的语言是什么?我必须使用Android版本2.1(api level 7)来实现这一点。
请帮我实现这个功能。
致以敬意,
Piks
发布于 2012-06-06 18:04:55
你可以通过首先发送结果意图来检查它。
Intent intent = new Intent();
intent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(intent, 0);然后你可以用onActivityResult的方法检查一下是否安装了TTS引擎:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 0){
if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){
Toast.makeText(getApplicationContext(),"Already Installed", Toast.LENGTH_LONG).show();
} else {
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
Toast.makeText(getApplicationContext(),"Installed Now", Toast.LENGTH_LONG).show();
}希望它能正常工作:)
发布于 2015-09-16 05:57:51
这将为您提供安装在Android上的TTS引擎列表。
tts = new TextToSpeech(this, this);
for (TextToSpeech.EngineInfo engines : tts.getEngines()) {
Log.d("Engine Info " , engines.toString());
}发布于 2012-06-06 18:01:57
要保存您的点击:
启动此命令以检查是否安装了TTS:
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);然后得到这样的结果:
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);
}
}
}https://stackoverflow.com/questions/10911530
复制相似问题