Android进阶:Google自带语音播放功能实现
Android进阶:Google自带语音播放功能实现
在Android 中使用语音播放功能 只需要使用类 TextToSpeech ,该类实现了很多关于语音的功能,使用该类必须为其设置语言,现在支持五种语言,杯具的是不支持中文
实现很简单 不过首先要安装语言包 这个在设置--》语音输入和输出设置--》文字转语音设置
如下图
左边图中 安装语音数据 我这里已经安装成功了 所以是灰色的 如果没有安装这里就可以点 其他地方都是灰色的
安装文件4.28M 下载安装完成后就可以选择语言了 右图所示的五种语言 没有中文啊
下面来看实现 很简单
首先是layout文件:
- <?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/EditText01"
- android:layout_width="fill_parent"
- android:text="I hope so, because it's time to wake up."
- android:layout_height="wrap_content"
- />
- <Button
- android:id="@+id/Button01"
- android:text="开始播放"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
- </LinearLayout>
|
评论暂时关闭