0

我正在我的 Android 应用程序中实现 TTS(文本到语音)支持。我正在显示我的代码:

TextSpeech textSpeech = new TextSpeech();

 textToSpeech = new TextToSpeech(this, textSpeech);

 private class TextSpeech implements TextToSpeech.OnInitListener {
    @Override
    public void onInit(final int status) {
        if (status != TextToSpeech.ERROR) {

            if (TextToSpeech.LANG_AVAILABLE == textToSpeech.isLanguageAvailable(Locale.ENGLISH)) {

                Thread thread = new Thread() {
                    @Override
                    public void run() {
                        super.run();

                        textToSpeech.setLanguage(Locale.ENGLISH);

                        try {
                            for (int i = 0; i < 10; i++) {
                                if (Util.isGreaterThanApi21()) {
                                    textToSpeech.speak("" + i, TextToSpeech.QUEUE_FLUSH, null, null);
                                } else {
                                    textToSpeech.speak("" + i, TextToSpeech.QUEUE_FLUSH, null);
                                }
                                Thread.sleep(1000);
                            }
                        } catch (Exception exception) {

                        }
                    }
                };

                thread.start();
            } else {
                Toast.makeText(ViewWorkplanActivity.this, "Language Not Supported", Toast.LENGTH_SHORT).show();
            }
        }

    }

}

当我运行此代码时,某些设备缺少 3-4 个数字或需要 3-4 秒进行初始化。任何人都可以告诉我如何消除此错误吗?

4

0 回答 0