Android的文本到语音:onUtteranceCompleted()不解雇 [英] Android Text-to-Speech: onUtteranceCompleted() not fired

查看:230
本文介绍了Android的文本到语音:onUtteranceCompleted()不解雇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个文本到语音应用程序,onUtteranceCompleted永远不会被触发。 下面是我的一些code:

I'm working on a text to speech app, and onUtteranceCompleted never gets triggered. Here is some of my code:

    public class MyActivity extends Activity implements OnInitListener, OnUtteranceCompletedListener {

        private TextToSpeech tts;
        private HashMap<String, String> hashAudio;

        public void onInit(int status) {
            if (status == TextToSpeech.SUCCESS) {

                //defining hashAudio, its music!
                this.hashAudio = new HashMap<String, String>();
                this.hashAudio.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_MUSIC));
                this.tts.setOnUtteranceCompletedListener(this);

                this.readEnglish();
            }
        }


    public void readEnglish(){
            Log.v("MESSAGE", "reading english"); //gets shown

            this.hashAudio.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "english");
            this.tts.setLanguage(Locale.US);
            this.tts.speak("TEST", TextToSpeech.QUEUE_FLUSH, this.hashAudio);
           //gets read
        }

    public void onUtteranceCompleted(String uttId) {
            Log.v("MESSAGE", "Uterrance Completed");
            //never see this message
        }

会有人知道为什么吗?我已经通过几个主题走在这里的一些解决方案,但没有工作:(我也仔细阅读了Android文档:。(

Would anyone know why ? I've gone through a few topics in here with some solutions, but nothing worked :(. I've also read carefully the Android doc :(.

感谢您

推荐答案

好了,所以我想它了我自己,在我的code,唯一的问题是,

Ok so I figured it out myself, the only problem in my code was that

this.tts.setOnUtteranceCompletedListener(this);

被称为HashMap的实例化后。因此,最终code应该是这样的:

was called after the Hashmap was instantiated. So the final code should look like this:

this.tts.setOnUtteranceCompletedListener(this);
this.hashAudio = new HashMap<String, String>();
this.hashAudio.put(TextToSpeech.Engine.KEY_PARAM_STREAM,String.valueOf(AudioManager.STREAM_MUSIC));

这篇关于Android的文本到语音:onUtteranceCompleted()不解雇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆