我正在尝试使用 ARCWelder 将我的 android 应用程序移植到 Chrome。TextToSpeech 组件似乎不起作用。在一项活动中,我有一个不确定的进度循环,等待 TTS 引擎初始化。在 Chrome 上,它要么永远旋转,要么返回 NullPointerException。TTS 在 Chrome 中不可用吗?在 Chromebox 上运行 ChromeOS。
UtteranceProgressListener ttsListener = new UtteranceProgressListener() {
@Override
public void onStart(String s) {
Logg.d("speech started: " + s);
if (loadingDialog.isShowing()) {
loadingDialog.dismiss();
}
}
@Override
public void onDone(String s) {
Logg.d("speech done: " + s);
if (s.equals("1")) {
nextWord();
} else if (s.equals("2")) {
CheckLeave();
}
}
@Override
public void onError(String s) {
Logg.e("Text to Speech error speaking: " + s);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
showProgressDialog();
}
@Override
protected void onResume() {
if (tts==null) {
Logg.d("re-initializing TTS");
tts=new TextToSpeech(getApplicationContext(),
new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR){
tts.setSpeechRate(.5f + .25f * (Integer)KVDB.GetValue("speechRate",2));
tts.setLanguage(Locale.US);
if (pauseTime != 0) {
//Paused. Say nothing.
} else if (currentWord == null) {
startTime = new ExcelDate();
nextWord();
} else if (currentWord.length() == 0) {
nextWord();
} else {
reSpeak();
}
}
}
});
tts.setOnUtteranceProgressListener(ttsListener);
}
super.onResume();
}
private void showProgressDialog() {
loadingDialog = new ProgressDialog(this);
loadingDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
loadingDialog.setTitle(getString(R.string.test_loading_msg));
loadingDialog.show();
}