安卓文字转语音实例+代码+TextToSpeech的使用
来源:互联网 发布:js 判断对象类型 编辑:程序博客网 时间:2024/04/29 11:41
package example.com.myapplication;import android.content.Intent;import android.speech.tts.TextToSpeech;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.widget.Button;import android.widget.EditText;import java.util.Locale;public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //2,让TTS朗读起来 //onCreate方法中 //检查TTS是否正常 checkTts(); //创建用组件 final EditText speakValue = (EditText) findViewById(R.id.edtText); Button speakButton = (Button) findViewById(R.id.btnRead); speakButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String text = speakValue.getText().toString(); Log.d("result","text-->" +text); sayTts(text); } }); } //1,先写一个用来检查tts是否安装的方法 private final static int CHECK_CODE = 1; public void checkTts(){ Intent checkIntent = new Intent(); checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); startActivityForResult(checkIntent, CHECK_CODE); } //创建一个TTS private TextToSpeech mTts; //这个自己先去了解下onActivityResult是怎么回事,这里不作详解 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub super.onActivityResult(requestCode, resultCode, data); if(requestCode == CHECK_CODE){ if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){ //成功创建一个TTS mTts = new TextToSpeech(this, new TextToSpeech.OnInitListener() { @Override public void onInit(int i) { if(i == TextToSpeech.SUCCESS){ //设置语言区域 int result = mTts.setLanguage(Locale.US); //如果是不支持语言 if(result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED){ Log.e("error","不支持"); } } } }); }else{ //否则安装一个 Intent installIntent = new Intent(); installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); startActivity(installIntent); } } } //TTs朗读用 private void sayTts(String text){ //最简单的例子 mTts.speak(text, TextToSpeech.QUEUE_FLUSH, null); }}
1 0
- 安卓文字转语音实例+代码+TextToSpeech的使用
- 安卓文字转语音——其实可以很简单——TextToSpeech用法解析
- Android TTS 中文 文字转语音 使用TextToSpeech Svox
- Android TTS 中文 文字转语音 使用TextToSpeech Svox
- Android TTS 中文 文字转语音 使用TextToSpeech Svox .
- Android中使用TTS(TextToSpeech)将文字转为语音
- 使用TextToSpeech语音读取
- 使用TextToSpeech朗读文字
- TTS(TextToSpeech)将文本转为语音的简单使用
- TextToSpeech将文本转为语音的简单使用
- TextToSpeech将文本转为语音的简单使用
- 安卓TTS文字转语音
- 使用Svox实现中文转语音TextToSpeech(TTS)
- 使用Svox实现中文转语音TextToSpeech(TTS)
- 文字合成语音TextToSpeech语音解决中文不能用问题
- TextToSpeech的使用
- TextToSpeech的使用
- 百度文字转语音免费接口使用实例
- Java设计模式23种(搞笑版)
- 关于iOS项目中建有PCH文件,项目拷贝到别的电脑上运行报pch文件找不到的问题
- hibernate主键生成策略总结
- 文章标题AS中删除module
- 点击Edittext之外的区域软键盘的显示和隐藏
- 安卓文字转语音实例+代码+TextToSpeech的使用
- 微服务架构下的数据一致性:可靠事件模式
- 高斯消元
- Linux系统文件路径映射到windows资源管理器(NFS网络文件系统)
- jQuery EasyUI使用教程使用Ajax提交表单
- 栖息
- Provider is not a pattern by Mark Seemann
- 3784: 树上的路径
- ListView RecyclerView使用EmptyView