14_TTS
TTS(Text to speech)为语音合成的意思。本课程主要介绍了TTS的使用方法。

1 package cn.eoe.tts;
2
3 import java.util.Locale;
4 import android.annotation.SuppressLint;
5 import android.app.Activity;
6 import android.os.Bundle;
7 import android.speech.tts.TextToSpeech;
8 import android.view.View;
9 import android.view.View.OnClickListener;
10 import android.widget.Button;
11 import android.widget.TextView;
12 import android.widget.Toast;
13
14 @SuppressLint("NewApi") public class Main extends Activity implements TextToSpeech.OnInitListener,
15 OnClickListener {
16 private TextToSpeech tts;
17 private TextView textView;
18
19 @Override
20 public void onCreate(Bundle savedInstanceState) {
21 super.onCreate(savedInstanceState);
22 setContentView(R.layout.main);
23 tts = new TextToSpeech(this, this);
24
25 Button button = (Button) findViewById(R.id.button);
26 textView = (TextView) findViewById(R.id.textview);
27 button.setOnClickListener(this);
28 }
29
30 public void onClick(View view) {
31 tts.speak(textView.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
32 }
33
34 @Override
35 public void onInit(int status) {
36 if (status == TextToSpeech.SUCCESS) {
37 int result = tts.setLanguage(Locale.US);
38 if (result == TextToSpeech.LANG_MISSING_DATA
39 || result == TextToSpeech.LANG_NOT_SUPPORTED) {
40 Toast.makeText(this, "Language is not available.",
41 Toast.LENGTH_LONG).show();
42 }
43 }
44
45 }
46
47 }
Main
1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:orientation="vertical" >
6
7 <Button
8 android:id="@+id/button"
9 android:layout_width="fill_parent"
10 android:layout_height="wrap_content"
11 android:text="说话" />
12
13 <TextView
14 android:id="@+id/textview"
15 android:layout_width="fill_parent"
16 android:layout_height="fill_parent"
17 android:text="@string/text" />
18
19 </LinearLayout>
main.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <resources>
3 <string name="hello">Hello World, Main!</string>
4 <string name="app_name">朗读文本</string>
5 <string name="text">Android 2.1 is a minor platform release deployable
6 to Android-powered handsets starting in January 2010. This release
7 includes new API changes and bug fixes. For information on changes,
8 see the Framework API section.\n
9
10 For developers, the Android 2.1 platform is available as a downloadable
11 component for the Android SDK. The downloadable platform includes a
12 fully compliant Android library and system image, as well as a set of
13 emulator skins, sample applications, and more. The downloadable
14 platform includes no external libraries.\n
15
16 To get started developing or testing against the Android 2.1 platform,
17 use the Android SDK and AVD Manager tool to download the platform into
18 your Android SDK. For more information, see Adding SDK Components.
19 </string>
20 </resources>
strings.xml
14_TTS的更多相关文章
随机推荐
- P6064 [USACO05JAN]Naptime G
最近做了多少道 usaco 了,连 FJ 都认识我了呀 题意描述 传送门 给你 \(N\) 段时间其中 \(B\) 段时间你要用来睡眠,再给你每个时间睡眠可获得的效用值 \(U_i\). 可惜的是你每 ...
- 【原创】ARM平台内存和cache对xenomai实时性的影响
目录 1. 问题概述 2. stress 内存压力原理 2. cache 因素 2.1 未加压 2.2 加压(cpu/io) 3. 内存管理因素 3.1 内存分配/释放 3.2 MMU拥塞 4 总结 ...
- python xmind转Excel(puppet洛洛原创)
需求:将xmind文件转为Excel文件,并添加UI界面操作以降低操作难度. 这个需求一句话就讲清楚了,但实际上还需要做很多工作: 1,了解Xmind文件结构 2,提取Xmind文件分支内容(重点) ...
- Flutter(75):Sliver组件之SliverFixedExtentList
Flutter教学目录持续更新中 Github源代码持续更新中 1.SliverFixedExtentList 可以固定Item高度的SliverList 2.SliverFixedExtentLis ...
- python_摘要_加密
import hashlib def get_md5(username,password): md5 = hashlib.md5(username.encode('utf-8')) # 加盐 md5. ...
- nginx&http 第三章 ngx 请求处理的 11 个阶段 --ngx_http_process_request& ngx_http_handler
ngx_http_process_request如果设置了定时器则删除,既然所有的请求已经接收完毕,就不会再发生超时了 重设连接的读写回调函数 重设请求读事件回调函数 调用 ngx_http_hand ...
- Netlink 内核实现分析 4
netlink 库函数: http://www.infradead.org/~tgr/libnl/doc/core.html#core_netlink_fundamentals #define NET ...
- fcntl函数用法——设置文件锁
fcntl函数.锁定文件,设置文件锁.设置获取文件锁:F_GETLK .F_SETLK .F_SETLKW文件锁结构,设置好用于fcntl函数的第三个参数.struct flock{ shor ...
- Spring源码之IOC容器创建、BeanDefinition加载和注册和IOC容器依赖注入
总结 在SpringApplication#createApplicationContext()执行时创建IOC容器,默认DefaultListableBeanFactory 在AbstractApp ...
- [LeetCode题解]21. 合并两个有序链表 | 递归
解题思路 使用递归实现: 定义函数功能:合并两个有序链表,并返回链表的头 结束条件:两个链表其中一个为空,返回另一个链表 递推公式: l1.val < l2.val:l1.next = Merg ...