初学Android,自动朗读TTS(五十二)
2012-09-19 10:47
387 查看
Android提供了自动朗读功能TTS(TextToSpeech),有些人用过一些听书软件,就是把文字念出来,听起来不错,不过TTS目前并不支持中文(难道又是一个鸡肋?)
API详解
http://wang-peng1.iteye.com/blog/572849
下面做个简单的例子
朗读出来是一个成年女性的声音,语速有些快,不知道这个能不能调节
API详解
http://wang-peng1.iteye.com/blog/572849
下面做个简单的例子
朗读出来是一个成年女性的声音,语速有些快,不知道这个能不能调节
package WangLi.IO.Speech; import java.util.Locale; import android.app.Activity; import android.os.Bundle; import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech.OnInitListener; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class Speech extends Activity { TextToSpeech tts; EditText editText; Button speech; Button record; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //初始化TextToSpeech对象 tts = new TextToSpeech(this,new OnInitListener() { @Override public void onInit(int status) { //如果装载TTS引擎成功 if(status == TextToSpeech.SUCCESS) { //设置使用美式英语朗读(虽然设置里有中文选项Locale.Chinese,但并不支持中文) int result = tts.setLanguage(Locale.US); //如果不支持设置的语言 if(result != TextToSpeech.LANG_COUNTRY_***AILABLE && result != TextToSpeech.LANG_***AILABLE) { Toast.makeText(Speech.this, "TTS暂时不支持这种语言朗读", 50000).show(); } } } }); editText = (EditText)findViewById(R.id.txt); speech = (Button)findViewById(R.id.speech); record = (Button)findViewById(R.id.record); speech.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { //执行朗读 tts.speak(editText.getText().toString(), TextToSpeech.QUEUE_ADD, null); }}); record.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { //将朗读文本的音频记录到指定文件 tts.synthesizeToFile(editText.toString().toString(), null, "/sdcard/sound.wav"); Toast.makeText(Speech.this, "声音记录成功", 50000).show(); }}); } @Override public void onDestroy() { //关闭TextToSpeech对象 if(tts != null) tts.shutdown(); } }
相关文章推荐
- Android自动朗读(TTS)的实现
- Android 自动朗读(TTS)
- Android自动朗读(TTS)的实现
- Android中自动朗读(TTS)的简单使用
- Android的数据存储和IO - 自动朗读(TTS)
- Android的数据存储和IO - 自动朗读(TTS)
- Android中的自动朗读(TTS)
- Android中的自动朗读(TTS)
- Android自动朗读(TTS)
- Android开发之自动朗读TTS用法分析
- Android 通过手说tts中文语音包实现中文朗读
- Android开发之文本内容自动朗读功能实现方法
- Android应用开发提高篇(2)-----文本朗读TTS(TextToSpeech)
- 所有的R.都报错了 包括自动生成的代码 小弟初学Android 希望各位前辈多多指教 谢谢了
- android 自动朗读功能
- Android 自动朗读TT
- Android TTS学习 连续朗读
- Andorid自动朗读TTS使用
- 借助“手说”免费应用软件,实现中文朗读(Android TTS实践)
- 安卓初学:Android实现输入文本自动匹配提示效果总结