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)
我面临几个问题:
难道我做错了什么?或者只是谷歌眼镜不支持TTS,甚至认为很难相信.
欢迎任何建议!非常感谢你!:)
您是否有可能在初始化 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。
| 归档时间: |
|
| 查看次数: |
928 次 |
| 最近记录: |