package com.anyun.exam.lib.util;
|
|
import android.content.Context;
|
import android.speech.tts.TextToSpeech;
|
import android.util.Log;
|
|
import com.anyun.exam.lib.RemoteService;
|
|
import java.util.Locale;
|
|
public class Speaker {
|
private Context context;
|
private TextToSpeech tts;
|
|
final public String TAG = Speaker.class.getCanonicalName();
|
|
public Speaker(final Context context) {
|
// TODO Auto-generated constructor stub
|
Log.d(TAG, "Speaker Init...");
|
this.context = context;
|
tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
|
@Override
|
public void onInit(int status) {
|
Log.d(TAG, "onInit TextToSpeech.SUCCESS");
|
|
// TODO Auto-generated method stub
|
if (status == TextToSpeech.SUCCESS)
|
{
|
Log.d(TAG, "TextToSpeech.SUCCESS");
|
int result = tts.setLanguage(Locale.CHINA);
|
|
if (result == TextToSpeech.LANG_MISSING_DATA
|
|| result == TextToSpeech.LANG_NOT_SUPPORTED)
|
{
|
Log.d(TAG, "TextToSpeech.LANG_NOT_SUPPORTED");
|
}
|
}
|
}
|
});
|
}
|
|
public void speak(String text) {
|
Log.d(TAG, "SPEAK");
|
// tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
|
tts.speak(text, TextToSpeech.QUEUE_ADD, null, "speech");
|
}
|
}
|