Android(安卓)自带TTS 使用
android 自带的tts类为TextToSpeech
我们需要new出方法的实例
mSpeech = new TextToSpeech(MainActivity.this, new TTSListener());
设置播放语言
mSpeech.setLanguage(Locale.ENGLISH);
private class TTSListener implements OnInitListener {
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS) {
//int result = mSpeech.setLanguage(Locale.ENGLISH);
int result = SetLanguage(curLang);
//如果打印为-2,说明不支持这种语言
Toast.makeText(MainActivity.this, “————-result = ” + result, Toast.LENGTH_LONG).show();
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
System.out.println(“————-not use”);
} else {
mSpeech.speak(“i love you”, TextToSpeech.QUEUE_FLUSH, null);
}
}
}
}
调用播放方法
if(mSpeech != null)
{
mSpeech.stop();
mSpeech.shutdown();
mSpeech = null;
}
// 创建TTS对象
mSpeech = new TextToSpeech(MainActivity.this, new TTSListener());
更多相关文章
- Android关闭其他程序
- android --相机使用详解概述
- Android底部导航栏实现(四)之TabLayout+ViewPager
- 在android里保存数据的三种形式(Saving Data)
- LayoutInflater.inflate()方法的介绍
- 使用ListView应该注意的地方
- Service实例-播放mp3音乐
- onRetainNonConfigurationInstance和getLastNonConfigurationIns
- Android学习笔记三