Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is TextToSpeech supported on Google Glass?

I was wondering if TextToSpeech is supported on Google Glass?

I did something like this:

public class TextToSpeechController implements TextToSpeech.OnInitListener{

private Context mContext;

private TextToSpeech tts;

public TextToSpeechController(Context context) {
    Log.e("TEXT TO SPEECH CONTROLLER", "controller");
    mContext = context;
    tts = new TextToSpeech(context, this);
}

@Override
public void onInit(int status) {
    Log.e("INIT TTS", "INIT");
    if (status == TextToSpeech.SUCCESS) {
            int result = tts.setLanguage(Locale.ENGLISH);

            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                   Toast.makeText(mContext, "This Language is not supported", Toast.LENGTH_LONG).show();
            }
            else {
                Toast.makeText(mContext, "Ready to Speak", Toast.LENGTH_LONG).show();
                speakTheText("Welcome to Vision Screening App");
            }

    } 
    else {
         Toast.makeText(mContext, "Can Not Speak", Toast.LENGTH_LONG).show();
    }   
}

public void stopTTS(){
    Log.e(".....TTS", "SHUTDOWN");
    tts.stop();
    tts.shutdown();
}

 public void speakTheText(String str){
     Log.e("SPEAK TEXT!!!!", "SPEAK TEXT");
     tts.speak(str, TextToSpeech.QUEUE_FLUSH, null);
 }

}

and in my Activity (onCreate) I have:

controller_tts = new TextToSpeechController(getApplicationContext());

I face several problems :

  1. First of all the onInit method is not called at all, only at the moment when I exit the current Activity.
  2. Somehow, after using TTS, the speeker's volume turns to mute and I cannot turn the volume back from the settings(only after I reboot the Glasses)

Am I doing something wrong? or simply Google Glass does not support TTS, even thought is hard to believe that.

Any suggestion is welcome! Thank you very much!:)

like image 887
Ispas Claudiu Avatar asked Sep 30 '22 01:09

Ispas Claudiu


1 Answers

Is it possible that you are calling stopTTS before TextToSpeech is initialized?

This works just fine for me on Glass:

import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.MotionEvent;
import android.widget.TextView;

import java.util.Locale;

public class TTSTestActivity extends Activity 
  implements TextToSpeech.OnInitListener {

  private TextToSpeech tts;
  private boolean initialized = false;
  private String queuedText;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView view = new TextView(this);
    view.setText("Tap Me");
    setContentView(view);
    tts = new TextToSpeech(this /* context */, this /* listener */);
  }

  @Override
  public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
      initialized = true;
      tts.setLanguage(Locale.ENGLISH);

      if (queuedText != null) {
        speak(queuedText);
      }
    }
  }

  public void speak(String text) {
    // If not yet initialized, queue up the text.
    if (!initialized) {
      queuedText = text;
      return;
    }
    queuedText = null;
    // Before speaking the current text, stop any ongoing speech.
    tts.stop();
    // Speak the text.
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
  }

  @Override
  public boolean onGenericMotionEvent(MotionEvent event) {
    // On any motion event (including touchpad tap), say 'Hello Glass'
    speak("Hello Glass");
    return true;
  }
}

With this example, anytime you tap the touch pad (or cause any other type of motion event), you should hear "Hello Glass." Note that if text is provided before TextToSpeech has initialized, then this is queued and then spoken after initialization is a success.

This does not include any tear-down, but to do that you can always put stop/shutdown of TextToSpeech in onDestroy() of the activity.

like image 146
Brandon Wuest Avatar answered Dec 16 '22 10:12

Brandon Wuest