Android提供了自动朗读支持。
TextToSpeech(Context context, TextToSpeech.OnInitListener listener)
setLanguage(Locale loc)。如果调用setLanguage(Locale loc)的返回值是 TextToSpeech.LANG_COUNTRY_AVAILABLE 则说明当前TTS系统可以支持所设置的语言、国家选项。
speak(String text, int queueMode, HashMap params)
synthesizeToFile(String text, HashMap params, String filename)
TextToSpeech.QUEUE_FLUSH
TextToSpeech.QUEUE_ADD
归纳起来,使用TextToSpeech引擎的步骤如下:
(1)创建TextToSpeech对象,创建时传入OnInitListener监听器监听创建是否成功。
(2)设置TextToSpeech所使用语言、国家选项,通过返回值判断TTS是否支持该语言、国家选项。
(3)调用speak或synthesizeToFile方法。
(4)关闭TTS,释放资源。
src\org\crazyit\io\Speech.java
package org.crazyit.io;
import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitLis