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的更多相关文章
随机推荐
- 浅析I/O模型-select、poll、epoll
I/O流 概念 (1)c++中将数据的输入输出称之为流(stream),在c++中,流被定义为类,成为流类(stream class),其定义的对象为流对象. (2)文件,套接字(socket),管道 ...
- .netcore简单使用hangfire
Hangfire简介 Hangfire是一个开源的任务调度框架,它内置集成了控制页面,很方便我们查看,控制作业的运行:对于运行失败的作业自动重试运行.它支持永久性存储,支持存储于mssql,mysql ...
- CF1008D Pave the Parallelepiped
容斥原理 解法一: 其他容斥原理的题也可以用这种思想 先把$A$,$B$,$C$分解因数 一种很暴力的想法是,将这些因数分成若干个集合(画出韦恩图),然后对有序数组的三个数分别枚举其位于哪一个集合中 ...
- JavaScript之构造函数
在学习构造函数之前我们需要知道我们学习构造函数需要学习什么: 1.什么是构造函数 2.构造函数用来做什么 3.构造函数的执行过程 4.构造函数的返回值 1.所以首先我们需要知道什么是构造函数: 在 ...
- c# sqlhlpear
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...
- 9个JavaScript日常开发小技巧
1.生成指定范围的数字 在某些情况下,我们会创建一个处在两个数之间的数组.假设我们要判断某人的生日是否在某个范围的年份内,那么下面是实现它的一个很简单的方法 1 2 3 4 5 6 let start ...
- 关于 node build/build.js 卡顿的问题
今天也是奇了怪了,npm run dev 可以正常执行,但node build/build.js 就死活不行,卡住不动 实在不行,就有了"重启"万能大法,结果依然不行.实在无奈, ...
- 使用Ganglia监控系统监控集群(debian)
ganglia是一个集群监控软件,底层使用RRDTool获得数据. Ganglia分为ganglia-monitor和gmetad两部分,前者运行在集群每个节点上(被监控机器)收集RRDTool产生的 ...
- 工作流(workflow)
1,JBPM 工作流(开源历史悠久) 2,activity 工作流(开源历史悠久) 3,workable 工作流(功能比较强大,但是开源维护缓慢,比较注重商业化) 以上三个是主流的工作流
- abp(net core)+easyui+efcore实现仓储管理系统——出库管理之六(五十五)
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统--ABP总体介绍(一) abp(net core)+ ...