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());
更多相关文章
- C语言函数以及函数的使用
- LayoutInflater.inflate()方法的介绍
- android 笔记 --- 自定义Android主题风格theme.xml方法
- android工程下运行main方法的配置方法
- Android Studio无法新建创建android工程解决方法
- Android Studio设置主题 和 不支持中文的问题解决方法
- Flutter下载更新App的方法示例
- android map的使用方法