搜索
查看
编辑修改
首页
UNITY
NODEJS
PYTHON
AI
GIT
PHP
GO
CEF3
JAVA
HTML
CSS
搜索
编程挑战者
这个屌丝很懒,什么也没留下!
关注作者
热门标签
jquery
HTML
CSS
PHP
ASP
PYTHON
GO
AI
C
C++
C#
PHOTOSHOP
UNITY
iOS
android
vue
xml
爬虫
SEO
LINUX
WINDOWS
JAVA
MFC
CEF3
CAD
NODEJS
GIT
Pyppeteer
article
热门文章
1
openpose安装(Linux_ubuntu_16.04+cuda9+cudnn7.1.4+protobuf2.6.1)_openpose linux
2
TensorRT加速方法介绍(python pytorch模型)_detected invalid timing cache, setup a local cache
3
[halcon]--图像锐化--索贝尔、拉普拉斯_halcon 锐化
4
题解 CF283E 【Cow Tennis Tournament】
5
飞桨社区项目PaddleMM正式进入木兰开源社区进行孵化
6
深拷贝与浅拷贝的区别以及Object.assign()用法_阐述object.assign的用法,深拷贝与浅拷贝的区别?
7
云上无极限:亚马逊云科技开启开发者新纪元
8
【软件设计师-中级——刷题记录6(纯干货)】_软件设计师近几年题目
9
手把手教会你docker之环境搭建_docker搭建
10
微服务架构与SpringCloud
当前位置:
article
> 正文
Android 通过手说tts中文语音包实现中文朗读
作者:编程挑战者 | 2024-02-02 13:30:51
赞
踩
android tts 绑定服务
Android 通过手说tts中文语音包实现中文朗读
关于手说tts中文语音包的详细资料可以查看官网 [url]http://shoushuo.com/index.html[/url]
手说TTS,是Android平台下的中文语音引擎,提供了中文文本到语音的转换。
使用手说TTS进行中文文本的朗读,包括中文简繁体、阿拉伯数字、英文字母及一些符号的混读。并且处理了中文的多音字和音调转换等问题。
开发人员可以使用手说TTS来开发Android平台下需要中文语音的应用程序。
开发准备:
第一步:安装手说TTS安装包
从官网 [url]http://shoushuo.com/sstts.html[/url] 下载手说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代码:
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);
}
}
}
声明:
本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:
https://www.wpsshop.cn/article/detail/55448
推荐阅读
article
单片机
、ARM、嵌入式开发、Android 底层开发有什么关系?...
在应用方面,可以当做高级
单片机
直接使用,但为了高效的管理资源(软硬)以及扩展的方面,通常给其运行操作系统,这样就把所有的...
赞
踩
article
Android studio中文汉化详细教程_
android
studio
汉化...
android
studio
在之前实现中文汉化比较简单,只需要在Plugins中搜索chinese下载插件安装即可实现汉...
赞
踩
article
Android Studio|使用SqLite实现一个简单的登录注册功能_android studi...
Android Studio 是开发 Android 应用程序的官方 IDE,基于 Intellij IDEA。你可以从...
赞
踩
article
Android 样式小结_在程序的res/values/styles.xml文件中创建一个名为hli...
样式可以定义界面的格式和外观。样式可应用于单个 View(从布局文件中)或应用于整个 Activity 或应用(从清单文...
赞
踩
article
We recommend using a newer Android Gradle plugin t...
在gradle.properties里添加“
android
.suppressUnsupportedCompileSdk=...
赞
踩
article
鸿蒙剥离 AOSP 不兼容 Android 热门问题汇总,不吹不黑不吵_鸿蒙4 官网
android
...
好了,目前主要的问题就这些,如果有什么问题欢迎大家「心平气和」地讨论,如果有什么有用的新话题点,到时候会补充上来。我不是...
赞
踩
article
Duplicate class
kotlin
.collections.jdk8.Collection...
我使用
java
代码 构建项目,初始代码运行就会报错。我使用的是Android Studio Giraffe(Adroid...
赞
踩
article
Android WebView 报错 ( 网页无法打开 位于
http
://... 的网页无法加载,...
这意味着,如果应用程序尝试连接到一个不安全的 HTTP 网站,将收到 net::ERR_CLEARTEXT_NOT_PE...
赞
踩
article
Android 14
媒体
权限变化_read_media_images...
在Android 14设备上与您的应用程序交互的用户现在可以在应用程序请求Android 13(API级别33)中引入的...
赞
踩
article
Android Studio实现钢琴块小游戏_
android
游戏源码...
钢琴块(别踩白块)是一款非常受欢迎的益智游戏,游戏的玩法很简单。游戏界面由多行黑白相间的方块组成,玩家需要尽量不要踩到白...
赞
踩
article
Android
输入
系统介绍...
最近接触到了一个问题:耳机插入事件的由来,走读了下IMS
输入
系统服务的源码。同时,IMS
输入
系统服务在
Android
的开...
赞
踩
article
企业的
Android
移动
设备
管理
(
MDM
) 解决方案...
Mobile Device Manager Plus
移动
设备
管理
软件,IT
管理
员可以使用它来
管理
Android
设备
,可...
赞
踩
article
Android
Firebase
(
FCM
)
推送
接入...
Firebase
消息
推送
Android
Firebase
(
FCM
)
推送
接入 官方文档: 向后...
赞
踩
article
Android
mk
文件
...
apk
文件
和mk
文件
在同级目录。
Android
mk
文件
1.编...
赞
踩
article
android
13.0
Launcher3
长按
app
弹窗
设置为圆角
背景
功能
实现二...
在
13.0
的系统ROM定制化开发中,在进行一些
Launcher3
的定制化开发中,在使用
app
的
弹窗
的
功能
时,会弹出应用信...
赞
踩
article
Android
Serializable
和
Parcelable
的
详解以及
代码
示例(
Kotlin
...
Serializable
方便Java中对象
的
序列化,可将对象存储在存储设备上。而`
Parcelable
主要用于内存序列化...
赞
踩
article
Android
判断
网络
wifi
是否
可用
工具类...
【代码】
Android
判断
网络
wifi
是否
可用
工具类。
Android
判断
网络
wifi
是否
可用
工具类 ...
赞
踩
article
国内镜像:极速下载编译
WebRTC
源码(
For
Android
/
Linux
/IOS)(二十四)...
本篇目的:国内镜像:极速下载编译
WebRTC
源码(
For
Android
/
Linux
/IOS)国内镜像:极速下载编译We...
赞
踩
article
【
Unity
】
Attribute
meta-
data
#com.google.
android
.
play
...
Max聚合安装了多个广告源,不确定是哪个广告的SDK依赖更高版本结算库,导致SDK依赖和IAP依赖冲突。2、Max由6....
赞
踩
article
解决编译失败 Attribute
meta
-
data
#
android
.
support
.
VERSION
...
报错如下: Attribute
meta
-
data
#
android
.
support
.
VERSION
@
value
valu...
赞
踩
相关标签
单片机
51单片机
android studio
android
ide
java
sqlite
数据库
开发语言
harmonyos
华为
android-studio
kotlin
http
网络协议
媒体
ui