Created
November 17, 2011 11:24
-
-
Save simekadam/1372947 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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