Saw a couple of posts from people looking for info on the new text to
speech library so I had a whirl at getting it running.
Seems to work without any kind of permissions or anything - took about
5 minutes, I must say I'm really impressed!
I'm sure this probably isn't best practice but it works :)
public class Traffic extends Activity implements OnInitListener {
TextToSpeech _tts;
boolean _ttsActive = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onPause(){
super.onPause();
try{
// Stop talking when we lose focus
if (_tts != null){
_tts.stop();
_ttsActive = false;
}
}catch(Exception e){}
}
@Override
public void onResume(){
super.onResume();
// Create our text to speech object.
_tts = new TextToSpeech(getApplicationContext(), this);
}
@Override
public void onDestroy(){
super.onDestroy();
try{
// We're closing down so kill it with fire.
if (_tts != null){
_tts.shutdown();
_tts = null;
}
powerLock.release();
}
catch(Exception e){}
}
@Override
public void onInit(int status) {
// If the TTS init is successful set a flag to say we
can be used; say hello
if (status == TextToSpeech.SUCCESS){
_ttsActive = true;
_tts.speak("Hello world. mmm donuts",
TextToSpeech.QUEUE_FLUSH, null);
}
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---