Is TextToSpeech supported in Google Glass?

I was wondering if TextToSpeech is supported in 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 work (onCreate) I have:

 controller_tts = new TextToSpeechController(getApplicationContext()); 

I am facing several issues:

  • First of all, the onInit method is not called at all, only at the moment when I exit the current Activity.
  • Anyway, after using TTS, the caster’s volume is turned off, and I can’t return the volume from the settings (only after restarting the glasses)

Am I doing something wrong? or just Google Glass does not support TTS, it’s even hard to believe it.

Any suggestion is welcome! Many thanks!:)

+5
source share
1 answer

Is it possible that you call stopTTS before initializing TextToSpeech?

This works 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; } } 

In this example, when you press the touchpad (or trigger some other type of motion event), you should hear "Hello Glass". Note that if text is provided before TextToSpeech is initialized, it will be queued and then spoken after successful initialization.

This does not apply to breaking, but for this you can always stop / disable TextToSpeech in onDestroy() activity.

+4
source

Source: https://habr.com/ru/post/1200758/


All Articles