調(diào)用Android系統(tǒng)語音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("這里填入想要轉(zhuǎn)成語音的文字", TextToSpeech.QUEUE_FLUSH, null);