Skip to content

Instantly share code, notes, and snippets.

@simekadam
Created November 17, 2011 11:24
Show Gist options
  • Save simekadam/1372947 to your computer and use it in GitHub Desktop.
Save simekadam/1372947 to your computer and use it in GitHub Desktop.
public class SpeechHelper implements OnInitListener {
private static TextToSpeech mTts;
private String text; //data to speech
private static SpeechHelper helper;
public static SpeechHelper getInstance(){
if(helper == null){
helper = new SpeechHelper();
}
return helper;
}
public void say(String text, Context context){
if(mTts == null){
this.text = text;
mTts = new TextToSpeech(context, (OnInitListener) helper);
}
else{
mTts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
@Override
public void onInit(int status) {
// TODO Auto-generated method stub
if (status == TextToSpeech.SUCCESS) {
mTts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
public void stopTTS(){
if(mTts != null){
mTts.shutdown();
mTts.stop();
mTts = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment