altosdroid: begin adding TextToSpeech support.
authorMike Beattie <mike@ethernal.org>
Sun, 26 Aug 2012 11:38:33 +0000 (23:38 +1200)
committerMike Beattie <mike@ethernal.org>
Sun, 26 Aug 2012 11:38:33 +0000 (23:38 +1200)
Signed-off-by: Mike Beattie <mike@ethernal.org>
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java

index f8ab6dd3551e16fa639c73aea2cbbb61ff73ad8c..3e9998e5f09681b79c716aa6654cc7a9cd947b12 100644 (file)
@@ -31,6 +31,8 @@ import android.os.Handler;
 import android.os.Message;
 import android.os.Messenger;
 import android.os.RemoteException;
+import android.speech.tts.TextToSpeech;
+import android.speech.tts.TextToSpeech.OnInitListener;
 import android.text.method.ScrollingMovementMethod;
 import android.util.Log;
 //import android.view.KeyEvent;
@@ -84,6 +86,8 @@ public class AltosDroid extends Activity {
        // Local Bluetooth adapter
        private BluetoothAdapter mBluetoothAdapter = null;
 
+       private TextToSpeech tts;
+       private boolean tts_enabled = false;
 
        // The Handler that gets information back from the Telemetry Service
        static class IncomingHandler extends Handler {
@@ -183,6 +187,14 @@ public class AltosDroid extends Activity {
                        return;
                }
 
+               // Enable Text to Speech
+               tts = new TextToSpeech(this, new OnInitListener() {
+                       public void onInit(int status) {
+                               if (status == TextToSpeech.SUCCESS) tts_enabled = true;
+                               if (tts_enabled) tts.speak("AltosDroid ready", TextToSpeech.QUEUE_ADD, null );
+                       }
+               });
+
                // Start Telemetry Service
                startService(new Intent(AltosDroid.this, TelemetryService.class));
 
@@ -237,6 +249,8 @@ public class AltosDroid extends Activity {
 
                doUnbindService();
 
+               if (tts != null) tts.shutdown();
+
                if(D) Log.e(TAG, "--- ON DESTROY ---");
        }