TextToSpeech是否支持Google Glass?

Isp*_*diu 5 text-to-speech google-text-to-speech google-glass google-gdk

我想知道Google Glass是否支持TextToSpeech?

我做了这样的事情:

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);
 }
Run Code Online (Sandbox Code Playgroud)

}

在我的活动(onCreate)中,我有:

controller_tts = new TextToSpeechController(getApplicationContext());
Run Code Online (Sandbox Code Playgroud)

我面临几个问题:

  1. 首先,只有当我退出当前Activity时,才会调用onInit方法.
  2. 不知何故,使用TTS后,说话者的音量变为静音,我无法从设置中恢复音量(仅在我重新启动眼镜后)

难道我做错了什么?或者只是谷歌眼镜不支持TTS,甚至认为很难相信.

欢迎任何建议!非常感谢你!:)

Bra*_*est 4

您是否有可能在初始化 TextToSpeech 之前调用 stopTTS?

这对我来说在 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;
  }
}
Run Code Online (Sandbox Code Playgroud)

在此示例中,每当您点击触摸板(或引起任何其他类型的运动事件)时,您都应该听到“Hello Glass”。请注意,如果在 TextToSpeech 初始化之前提供文本,则会将其排队,然后在初始化成功后朗读。

这不包括任何拆卸,但要做到这一点,您可以随时在onDestroy()活动中停止/关闭 TextToSpeech。

  • AsyncTask 默认使用共享单线程执行器,因此 TTS 初始化也可能使用 AsyncTask。对于您的 AsyncTask,请尝试调用 `asyncTask.executeOnExecutor(Executors.newSingleThreadExecutor(), params)` 以查看是否会解锁 TTS 初始化。 (3认同)