调用Android系统语音TextToSpeech实例对象ide
具体代码写法以下:this
TextToSpeech mTextToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {code
@Override public void onInit(int status) {
if (status==TextToSpeech.SUCCESS) {对象
//设置语言朗读 int supported= mTextToSpeech.setLanguage(Locale.US); if ((supported!=TextToSpeech.LANG_AVAILABLE)&& (supported!=TextToSpeech.LANG_COUNTRY_AVAILABLE)) { Toast.makeText(this, "不支持当前语言!", Toast.LENGTH_SHORT).show(); } } } });
mTextToSpeech.speak("这里填入想要转成语音的文字", TextToSpeech.QUEUE_FLUSH, null);it