我正在创建一个使用文本到语音的应用程序,我希望用户能够脱机使用它,所以我检查一下tts数据是否安装在设备上,下面是执行此操作的thde代码:// Check tts data is installedIntent checkTTSIntent = new Intent();checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE);protected void onActivityResult(int requestCode, int resultCode, Intent data){ if(requestCode == MY_DATA_CHECK_CODE){ if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){ tts = new TextToSpeech(this, this); } else{ Intent installTTSIntent = new Intent(); installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installTTSIntent); } }}但这提示用户将德语、西班牙语、法语和意大利语作为四种下载选项进行安装,我如何才能只检查是否安装了意大利语等一种语言?我做了一些研究,但我正在努力寻找代码示例,使我能够实现这一点。 最佳答案 使用protected void onActivityResult(int requestCode, int resultCode, Intent data) {if (requestCode == MY_DATA_CHECK_CODE) { if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { tts = new TextToSpeech(this, this); } else { Intent installTTSIntent = new Intent(); installTTSIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); ArrayList<String> languages = new ArrayList<String>(); languages.add("it-IT"); // non sure if "it" is the right abbr for italian installTTSIntent.putStringArrayListExtra(TextToSpeech.Engine.EXTRA_CHECK_VOICE_DATA_FOR, languages); startActivity(installTTSIntent); } }}文档链接http://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine.html#EXTRA_CHECK_VOICE_DATA_FOR关于android - 如何检查设备上是否安装了文本到语音(TTS)的特定语言数据?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18134106/
10-11 14:14