1.介绍

2.xml文件布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity"
    android:gravity="center_horizontal">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="请输入需要朗读的文字:" />

        <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="10"
            android:inputType="textPersonName"
            android:text="" />
    </LinearLayout>

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="朗读" />
</LinearLayout>

3.java后台代码

package com.lucky.test43tts;

import android.speech.tts.TextToSpeech;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.Locale;

public class MainActivity extends AppCompatActivity {
    Button button1;
    EditText editText;
    TextToSpeech textToSpeech;//定义一个TTS

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button1=findViewById(R.id.button2);
        editText=findViewById(R.id.editText);
        //实例化TTS
        textToSpeech=new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                textToSpeech.setLanguage(Locale.CHINESE);  //设置朗读的语言类型
            }
        });
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //朗读内容
                textToSpeech.speak(editText.getText().toString(),TextToSpeech.QUEUE_ADD,null);
            }
        });
    }
}

Android 文字转语音(TTS)的更多相关文章

  1. Delphi文字转语音TTS【支持选择语音库,播放,暂停,开始,停止,生成语音文件,设置音量,设置语速】

    作者QQ:(648437169) 点击下载➨文字转语音TTS [Delphi 文字转语音TTS]调用系统自带的TTS组件,支持XP,vista,win7,win8,win10系统,支持选择语音库,播放 ...

  2. Android文字转语音引擎(TTS)使用

    百度网盘下载地址 密码:3si0资源来源:https://blog.csdn.net/Sqq_yj/article/details/82460580?utm_source=blogxgwz4 简单比较 ...

  3. Android文字转语音

    虽然视觉上的反馈通常是给用户提供信息最快的方式,但这要求用户把注意力设备上.当用户不能查看设备时,则需要一些其他通信的方法.Android提供了强大的文字转语音Text-to-Speech,TTS A ...

  4. Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(无图)

    注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYinYinQi ...

  5. Android实例-调用GOOGLE的TTS实现文字转语音(XE7+小米2)(XE10.1+小米5)

    相关资料: 注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYi ...

  6. Android技术分享-文字转语音并朗读

    Android技术分享-文字转语音并朗读 最近在做一个项目,其中有一个功能是需要将文本转换成语音并播放出来.下面我将我的做法分享一下. 非常令人开心的是,Android系统目前已经集成了TTS,提供了 ...

  7. 调用GOOGLE的TTS实现文字转语音(XE7+小米2)(XE10.1+小米5)

    相关资料: 注意:在手机上必须选安装文字转语音引擎“google Text To Speech”地址:http://www.shouji56.com/soft/GoogleWenZiZhuanYuYi ...

  8. TTS 文字转语音 ekho

    1.源码下载 使用svn客户端,执行如下命令下载 svn co https://svn.code.sf.net/p/e-guidedog/code/ 2.官方网站查看说明 http://www.egu ...

  9. 160617、使用espeak将文字转语音(TTS)

    http://www.eguidedog.net/cn/WebSpeech_cn.php 简单使用例子: <html> <head> <meta http-equiv=& ...

随机推荐

  1. 图论算法》关于SPFA和Dijkstra算法的两三事

    本来我是想把这两个算法分开写描述的,但是SPFA其实就是Dijkstra的稀疏图优化,所以其实代码差不多,所以就放在一起写了. 因为SPFA是Dijkstra的优化,所以我想来讲讲Dijkstra. ...

  2. SpringBoot15 sell02 订单模块

    1 订单模块 1.1 MySQL数据表 订单模块涉及到两个数据表: 订单表:主要存储订单相关的基本信息 DROP TABLE IF EXISTS `order_master`; CREATE TABL ...

  3. 跨平台的图形软件Dia

    一款非常不错的软件Dia,软件很小,免费.好用.跨平台(linux.windows.mac).可导出多种格式图片,除了流程图.UML建模图,还可以绘制其他很多图. ubuntu下可以直接通过命令行su ...

  4. Django框架 之 form组件的钩子

    Django框架 之 form组件的钩子 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3 ...

  5. Mybatis_映射文件_Select

    一.Select元素来定义查询操作 Id:唯一标识符.用来引用这条SQL语句,需要和接口的方法名一致 parameterType:参数类型.可以不传,MyBatis会根据TypeHandler自动推断 ...

  6. Requests接口测试(三)

    一.定制请求头 我们先来看一下,关于请求头的定制演示,相信了解http协议的小伙伴应该对请求头部headers请求头部并不陌生,那么作为实际工作中的我们,如果想自定义一些请求头的信息,我们应该怎么办呢 ...

  7. Python基础入门-数据类型

    一.变量 1)变量定义 在python中,我们可以把变量理解为一个值,变量是一个标签名,变量是有对应的一个值. name = 100(name是变量名 = 号是赋值号100是变量的值) 2)变量赋值 ...

  8. linux新的API signalfd、timerfd、eventfd使用说明

    原文:http://www.cfanz.cn/?c=article&a=read&id=46555注意很多当前(2013/8/6)线上运营的Linux内核可能不支持! 三种新的fd加入 ...

  9. delphi创建服务程序

    创建一个自己的服务程序: File -> New -> Other -> New(选项) -> Service Application 这样delphi会自动生成服务程序的框架 ...

  10. 微信运动数据抓取(Python)

    "微信运动"能够向朋友分享一个包含有运动数据的网页,网页中就有我们需要的数据.url类似于:http://hw.weixin.qq.com/steprank/step/person ...