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的更多相关文章
随机推荐
- typeerror object of type ‘decimal‘ is not json serializable jsonify
当使用flask的jsonify返回json数据时,由于数据库有些字段类型使用decimal,而jsonify无法处理 解决方案 导入下面的包即可解决 pip install simplejson
- NOIP 2017 Day1 解题报告
总分:100分 T1,小凯的疑惑, 100分 T2,时间复杂度,0分 T3,逛公园,0分 T1 ###题意简化: 给定两个互质的数字,输出最大不能表示的数: 基础数论题目 代码: #include&l ...
- 01_cifsd 高性能网络共享服务
01_cifsd 高性能网络共享服务 1.简介 cifsd 是一款高性能I/O网络文件共享服务, 通过一种与kernel直接交互的方式实现, github简介:https://github.com/n ...
- 基于MVC的RESTFul风格API实战
基于MVC的RESTful风格的实现 1.RESTful风格阐述 REST服务是一种ROA(Resource-Oriented Architecture,面向资源的架构)应用.主要特点是方法信息存在于 ...
- RabbitMq 基本命令
rabbitmqadmin 命令汇总: 命令 解释 rabbitmqadmin list users 查看所有用户 User rabbitmqadmin list users name 查看所有用户名 ...
- vue踩坑
1. 双向绑定的对象 改变或新增其属性 DOM不刷新问题 var obj = { "attr1": "1", "attr2": [2] }; ...
- 【SpringBoot】16. 如何监控springboot的健康状况
如何监控springboot的健康状况 SpringBoot1.5.19.RELEASE 一.使用Actuator检查与监控 actuaotr是spring boot项目中非常强大的一个功能,有助于对 ...
- 10、Django与Ajax
AJAX准备知识:JSON 什么是 JSON ? JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON 是轻量级的文本数据交换格式 JS ...
- leetcode24:word-ladder-ii
题目描述 给定两个单词(初始单词和目标单词)和一个单词字典,请找出所有的从初始单词到目标单词的最短转换序列: 每一次转换只能改变一个单词 每一个中间词都必须存在单词字典当中 例如: 给定的初始单词st ...
- Magic Method
Python 的 Magic Method 在 Python 中,所有以 "__" 双下划线包起来的方法,都统称为"魔术方法".比如我们接触最多的 __init ...