android TTS语音播放
来源:互联网 发布:resnet网络结构全貌 编辑:程序博客网 时间:2024/04/30 02:19
http://stephen830.iteye.com/blog/1183326
Android 通过手说tts中文语音包实现中文朗读
关于手说tts中文语音包的详细资料可以查看官网 http://shoushuo.com/index.html
手说TTS,是Android平台下的中文语音引擎,提供了中文文本到语音的转换。
使用手说TTS进行中文文本的朗读,包括中文简繁体、阿拉伯数字、英文字母及一些符号的混读。并且处理了中文的多音字和音调转换等问题。
开发人员可以使用手说TTS来开发Android平台下需要中文语音的应用程序。
开发准备:
第一步:安装手说TTS安装包
从官网 http://shoushuo.com/sstts.html 下载手说TTS安装包:ShoushuoTTS.apk 。
安装到真实手机或者手机模拟器中。
第二步:下载手说TTS客户类库包
下载手说TTS客户类库包:shoushuotts.jar 。
将该jar文件引入到你的应用中。
第二步:demo实现
xml文件
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <EditText
- android:id="@+id/edtSpeectText"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="太阳从东边升起,慢慢的露出红彤彤的笑脸。"
- />
- <Button
- android:id="@+id/btnSpeechGo"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="开始朗读"
- android:onClick="speechText"
- />
- </LinearLayout>
java代码:
- package com.zhouzijing.android.demo;
- import com.shoushuo.android.tts.ITts;
- import com.shoushuo.android.tts.ITtsCallback;
- import android.app.Activity;
- import android.content.ComponentName;
- import android.content.Context;
- import android.content.Intent;
- import android.content.ServiceConnection;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.IBinder;
- import android.os.Message;
- import android.os.RemoteException;
- import android.speech.tts.TextToSpeech;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- public class SpeechActivity extends Activity {
- private EditText edtSpeectText;
- private Button btnSpeechGo;
- private Context context;
- private ITts ttsService;
- private boolean ttsBound;
- /**
- * 定义Handler.
- */
- private final Handler handler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- Toast.makeText(context, " 我的话说完了 ", Toast.LENGTH_SHORT).show();
- btnSpeechGo.setEnabled(true);
- }
- };
- /**
- * 回调参数.
- */
- private final ITtsCallback ttsCallback = new ITtsCallback.Stub() {
- //朗读完毕.
- @Override
- public void speakCompleted() throws RemoteException {
- handler.sendEmptyMessage(0);
- }
- };
- /**
- * tts服务连接.
- */
- private final ServiceConnection ttsConnection = new ServiceConnection() {
- @Override
- public void onServiceDisconnected(ComponentName arg0) {
- try {
- //注册回调参数
- ttsService.unregisterCallback(ttsCallback);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- ttsService = null;
- ttsBound = false;
- }
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- ttsService = ITts.Stub.asInterface(service);
- ttsBound = true;
- try {
- //tts服务初始化
- ttsService.initialize();
- //撤销回调参数.
- ttsService.registerCallback(ttsCallback);
- } catch (RemoteException e) {
- }
- }
- };
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.speech_text);
- context = this;
- edtSpeectText = (EditText) findViewById(R.id.edtSpeectText);
- btnSpeechGo = (Button) findViewById(R.id.btnSpeechGo);
- }
- /**
- * 按钮:朗读.
- *
- * @param v
- */
- public void speechText(View v) {
- v.setEnabled(false);
- try {
- ttsService.speak(edtSpeectText.getText().toString(),
- TextToSpeech.QUEUE_FLUSH);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- @Override
- protected void onDestroy() {
- if (ttsBound) {
- ttsBound = false;
- //撤销tts服务
- this.unbindService(ttsConnection);
- }
- super.onDestroy();
- }
- @Override
- protected void onStart() {
- super.onStart();
- if (!ttsBound) {
- String actionName = "com.shoushuo.android.tts.intent.action.InvokeTts";
- Intent intent = new Intent(actionName);
- //绑定tts服务
- this.bindService(intent, ttsConnection, Context.BIND_AUTO_CREATE);
- }
- }
- }
0 0
- android TTS语音播放
- android tts 语音识别
- android TTS语音播报
- Android TTS语音识别
- Android中文TTS语音合成
- Android实战--语音合成TTS
- 【Android语音合成TTS】云知声离线TTS使用详解
- android 中文朗读 语音朗读 tts朗读
- Android中用TTS语音朗读一段英文
- Android TTS学习--使用中文语音
- Android中文语音合成(TTS)
- Android语音合成(TTS)SDK使用方法
- Android TTS文字转语音开发
- 关于Android文字转语音(TTS)开发
- Android 文本转语音TextToSpeech (TTS)
- Android文字转语音TTS离线程序
- Android TTS文本转语音TextToSpeech
- android 集成百度TTS 语音合成
- cocos2d-x学习笔记
- hdu 3836 Equivalent Sets
- mysql 执行大量insert语句
- java 大转盘摇奖算法
- c++ 读取位图信息显示位图 BITMAPINFOHEADER
- android TTS语音播放
- Android动画 fillAfter和fillBefore
- JAVA NIO 详解
- 福建机器人自动抛光机
- javascript基于原型的继承机制
- [安卓]2dx 转译集成了 uMeng 的 HelloWorld 项目到安卓
- 谆阻足谞揍专滓尊卓滋足着卒鬃籽奏注子
- 管理线程之向线程函数传递参数
- 设计模式与其使用原则