安卓TextToSpeech
Android允许您将文本转换为语音。您不仅可以转换它,还可以用多种不同的语言说文本。Android 为此提供了TextToSpeech类。为了使用此类,您需要实例化此类的对象并指定initListener。
创建 Empty Activity
我选择的API24,支持安卓7.0及以上的操作系统。
修改默认的 activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:transitionGroup="true">
<TextView android:text="文字转语音示例"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="35sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_marginTop