描述把文本讀出的API,在手機上測試知識支援英文,中文庫應該沒有是以不支援
實作步驟:
1.繼承TextToSpeech.OnInitListener
2.實作onInit方法在這裡加載語言int result = mTts.setLanguage(Locale.US);
3.初始化的執行個體TextToSpeech mTts = mTts = new TextToSpeech(this,
this // TextToSpeech.OnInitListener
);
4.調用其的speak方法private void sayHello() {
// Select a random hello.
int helloLength = HELLOS.length;
String hello = HELLOS[RANDOM.nextInt(helloLength)];
mTts.speak(hello,
TextToSpeech.QUEUE_FLUSH, // Drop all pending entries in the playback queue.
null);
}