/*
 * BRLTTY - A background process providing access to the console screen (when in
 *          text mode) for a blind person using a refreshable braille display.
 *
 * Copyright (C) 1995-2013 by The BRLTTY Developers.
 *
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU General Public License, as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any
 * later version. Please see the file LICENSE-GPL for details.
 *
 * Web Page: http://mielke.cc/brltty/
 *
 * This software is maintained by Dave Mielke <dave@mielke.cc>.
 */

package org.a11y.brltty.android;

import android.speech.tts.TextToSpeech;

public final class SpeechDriver {
  enum State {
    STOPPED,
    STARTED,
    FAILED
  }

  private static volatile State state = State.STOPPED;
  private static TextToSpeech tts = null;

  public static boolean start () {
    TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
      @Override
      public void onInit (int status) {
        state = (status == TextToSpeech.SUCCESS)? State.STARTED: State.FAILED;
      }
    };

    state = State.STOPPED;
    tts = new TextToSpeech(BrailleService.getBrailleService(), listener);
    return true;
  }

  public static void stop () {
    if (tts != null) {
      tts.shutdown();
      tts = null;
      state = State.STOPPED;
    }
  }

  public static boolean say (String text) {
    return tts.speak(text, TextToSpeech.QUEUE_ADD, null) == TextToSpeech.SUCCESS;
  }

  public static boolean mute () {
    return tts.stop() == TextToSpeech.SUCCESS;
  }

  public static boolean setVolume (float volume) {
    return false;
  }

  public static boolean setRate (float rate) {
    return tts.setSpeechRate(rate) == TextToSpeech.SUCCESS;
  }

  public static boolean setPitch (float pitch) {
    return tts.setPitch(pitch) == TextToSpeech.SUCCESS;
  }

  private SpeechDriver () {
  }
}

@@ -666,16 +666,43 @@
 droid;%0A%0A
+import java.util.HashMap;%0A%0A
 import a
@@ -733,16 +733,16 @@
 Speech;%0A
-
 %0Apublic 
@@ -921,16 +921,107 @@
  = null;
+%0A  private static final HashMap%3CString, String%3E parameters = new HashMap%3CString, String%3E();
 %0A%0A  publ
@@ -1380,16 +1380,40 @@
 tener);%0A
+    parameters.clear();%0A
     retu
@@ -1655,20 +1655,26 @@
 UE_ADD, 
-null
+parameters
 ) == Tex
@@ -1842,19 +1842,100 @@
     
-return fals
+parameters.put(TextToSpeech.Engine.KEY_PARAM_VOLUME, Float.toString(volume));%0A    return tru
 e;%0A 

Add speech volume support for Android. (dm)