Texttospeech (TTS) is an important new feature in Android 1.6. Converts the specified text to audio output in different languages. It can be easily embedded into games or applications to enhance user experience.
That is, "From Text to Speech" is part of human-machine interaction, allowing machines to speak. It is an outstanding work that uses both linguistics and psychology. With the support of built-in chips, it intelligently converts words into natural speech streams through the design of neural networks. TTS technology converts text files in real time. The conversion time can be calculated in seconds. With its unique Intelligent Voice controller, the voice and audio laws of text output are smooth, making the listener feel natural when listening to information, and there is no indifference or cool sense of machine speech output. The TTS Speech Synthesis Technology will cover the first and second-level Chinese characters of the national standard. It has an English interface to automatically identify Chinese and English and supports mixed Chinese and English reading. All voices adopt real-person Mandarin as the standard pronunciation, achieving rapid speech synthesis of-Chinese characters/second, reading speed up to 3-4 Chinese characters/second, enables users to hear clear and pleasant sound quality and consistent and smooth tone. A few MP3 players now have the TTS function.
(1). xml file
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <TextView android:id="@+id/speechTxt" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="you are very good !" /> <Button android:id="@+id/speechBtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="22dp" android:text="text to speech" /></RelativeLayout>
(2). Java File
Package fly. aty; import Java. util. locale; import android. app. activity; import android. OS. bundle; import android. speech. TTS. texttospeech; import android. speech. TTS. texttospeech. oninitlistener; import android. view. view; import android. view. view. onclicklistener; import android. widget. button; import android. widget. textview; import android. widget. toast; public class mainaty extends activity implements onclickliste NER, oninitlistener {private button speechbtn; // The button control starts to read private textview speechtxt; // Private texttospeech; // TTS object @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); speechbtn = (button) findviewbyid (R. id. speechbtn); speechbtn. setonclicklistener (this); speechtxt = (textview) findviewbyid (R. id. speechtxt); Te Xttospeech = new texttospeech (this, this); // The context parameter, texttospeech. oninitlistener}/*** is used to initialize the texttospeech engine * Status: success or error value * setlanguage setting language. The help document contains 22 types of * texttospeech. lang_missing_data: indicates the loss of language data. * Texttospeech. lang_not_supported: */@ overridepublic void oninit (INT status) {If (status = texttospeech. success) {int result = texttospeech. setlanguage (locale. US); If (result = texttospeech. lang_missing_data | result = texttospeech. lang_not_supported) {toast. maketext (this, "data loss or not supported", toast. length_short ). show () ;}}@ overridepublic void onclick (view v) {If (texttospeech! = NULL &&! Texttospeech. isspeaking () {texttospeech. setpitch (0.5f); // set the tone. The higher the value, the higher the sound (girl). The smaller the value, the male voice. 1.0 is the standard texttospeech. speak (speechtxt. gettext (). tostring (), texttospeech. queue_flush, null) ;}@ overrideprotected void onstop () {super. onstop (); texttospeech. stop (); // whether or not reading TTS is interrupted texttospeech. shutdown (); // close and release resources }}
Texttospeech (TTS) Function