onUtteranceCompleted 没有被调用?

发布于 2024-11-19 15:32:00 字数 482 浏览 1 评论 0原文

即使我设置正确:

HashMap<String, String> myHashRender = new HashMap<String, String>();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "utid");
mTts.speak("Speak something", TextToSpeech.QUEUE_ADD, myHashRender);

也在

mTts.setOnUtteranceCompletedListener(this);

onInit 函数中返回成功。 onUtteranceCompleted 仍然没有被调用。虽然有重复的问题,但我找不到答案。

我的 Activity 还实现了 OnUtteranceCompletedListener。

请帮忙。

Even though I am setting it correctly:

HashMap<String, String> myHashRender = new HashMap<String, String>();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "utid");
mTts.speak("Speak something", TextToSpeech.QUEUE_ADD, myHashRender);

also

mTts.setOnUtteranceCompletedListener(this);

in the onInit function return success.
Still the onUtteranceCompleted does not get called. Though there are duplicate questions, but no where I could find the answer.

My Activity also implements OnUtteranceCompletedListener.

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

羁拥 2024-11-26 15:32:00

在tts对象的onInit函数中调用setOnUtteranceCompletedListener。

如果要在调用 onUtteranceCompleted 函数时对 UI 进行任何更改,请在 runOnUIThread 方法中添加代码。

并且请记住在调用 talk() 函数时添加 Hashmap 参数值

示例:

TextToSpeech tts= new TextToSpeech(context, new OnInitListener() {

 @Override
 public void onInit(int status) {

    mTts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {

        @Override
        public void onUtteranceCompleted(String utteranceId) {

            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                //UI changes
                }
            });
        }
    });

 }
});


HashMap<String, String> params = new HashMap<String, String>();

params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"stringId");

tts.speak("Text to Speak",TextToSpeech.QUEUE_FLUSH, params);

Call the setOnUtteranceCompletedListener inside the onInit function of the tts object.

If you want to make any changes to the UI on the call of the onUtteranceCompleted function, add the code inside a runOnUIThread method.

And do remember to add the Hashmap param value while calling the speak() function

Example :

TextToSpeech tts= new TextToSpeech(context, new OnInitListener() {

 @Override
 public void onInit(int status) {

    mTts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() {

        @Override
        public void onUtteranceCompleted(String utteranceId) {

            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                //UI changes
                }
            });
        }
    });

 }
});


HashMap<String, String> params = new HashMap<String, String>();

params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"stringId");

tts.speak("Text to Speak",TextToSpeech.QUEUE_FLUSH, params);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文