I created some TTS Manager, because I want use someTTsObject.speak("some string")
in other classes.
This is my Manager class:
public class TtsManager
{
private TextToSpeech myTTS;
private Context context;
public TtsManager(Context baseContext)
{
this.context = baseContext;
initOrInstallTts();
}
public void initOrInstallTts()
{
myTTS = new TextToSpeech(context, new OnInitListener()
{
public void onInit(int status)
{
if (status == TextToSpeech.SUCCESS)
{
myTTS.setLanguage(Locale.US);
}
else
installTts();
}
});
}
private void installTts()
{
Intent installIntent = new Intent();
installIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
context.startActivity(installIntent);
}
public void speak(String text)
{
myTTS.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
and this is my main class, where I want to use that:
public class main extends Activity {
TtsManager tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tts = new TtsManager(this);
tts.speak("Welcome in my app");
}
}
When I run compilation I see on the LogCat:
08-30 17:25:52.531: I/TTS received:(2782): Welcome in my app
but i don't hear any text. I tested it on the virtual machine and phone.
Why that doesn't work? Cheers!