简体   繁体   English

Chrome ARC中的Android TextToSpeech

[英]Android TextToSpeech in Chrome ARC

I'm trying to port my android app to Chrome using ARCWelder. 我正在尝试使用ARCWelder将我的Android应用程序移植到Chrome。 The TextToSpeech component doesn't seem to work. TextToSpeech组件似乎不起作用。 In one activity I have an indeterminate progress circle waiting until the TTS engine is initialized. 在一项活动中,我有一个不确定的进度圈,一直等到初始化TTS引擎。 On Chrome, it either spins forever or returns a NullPointerException. 在Chrome上,它会永久旋转或返回NullPointerException。 Is TTS not available in Chrome? TTS在Chrome中不可用吗? Running ChromeOS on a Chromebox. 在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();
}

As you found, it does look like we don't have any kind of default TTS service provider as part of the ARC package. 如您所见,它看起来好像没有任何默认的TTS服务提供程序作为ARC软件包的一部分。 There is not one provided by the base Android OS at all. 基本的Android操作系统根本没有提供任何一个。

Please feel free to file a bug for it. 请随时提交错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM