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());

更多相关文章

  1. Android关闭其他程序
  2. android --相机使用详解概述
  3. Android底部导航栏实现(四)之TabLayout+ViewPager
  4. 在android里保存数据的三种形式(Saving Data)
  5. LayoutInflater.inflate()方法的介绍
  6. 使用ListView应该注意的地方
  7. Service实例-播放mp3音乐
  8. onRetainNonConfigurationInstance和getLastNonConfigurationIns
  9. Android学习笔记三

随机推荐

  1. android ProgressBar 的使用
  2. Android 原生加载框
  3. Activity去掉标题栏失败(使用AppCompat)
  4. 点击button然后改变其中文字的颜色
  5. android getResources的作用
  6. 在Android中通过代码切换到指定 WiFi
  7. Android通过http协议POST传输方式
  8. Android 系统菜单与自定义菜单
  9. android 安装 出现Android Native Develo
  10. Linux下Android ADB驱动安装详解