调用Android系统语音TextToSpeech实例对象
具体代码写法如下:
TextToSpeech mTextToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@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);
来源:oschina
链接:https://my.oschina.net/u/4285706/blog/4503554