本文介绍了TTS-UtteranceProgressListener不会被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不希望在这里把我的code,所以我只是把相关的部分。如果您需要更多,随意问。

我在使用文本到语音转换(TTS),这导致它问了一个问题之后...我通过TTS的OnInit的是被称为日志输出找到了一个演讲的听众,但UtteranceProgressListener是不是和我不其中的原因。任何帮助是AP preciated。

  // ---初始化变量TTS ---        //实现文本到语音功能
        TTS =新的文字转语音(这一点,新ttsInitListener());        //设置监听器TTS引擎
        tts.setOnUtteranceProgressListener(新ttsUtteranceListener());        如果(!tts.isSpeaking()){
            tts.speak(你要我,TextToSpeech.QUEUE_FLUSH,NULL);
        }


  // ---文本到语音和放大器;&安培;语音到文本方法---类ttsInitListener实现OnInitListener {    @覆盖
    公共无效的OnInit(INT状态){        如果(状态== TextToSpeech.SUCCESS){
            tts.setLanguage(Locale.getDefault());        }其他{
            TTS = NULL;
            Toast.makeText(mContext,无法初始化TTS引擎。
                    Toast.LENGTH_SHORT).show();
        }
    }
}类ttsUtteranceListener扩展UtteranceProgressListener {    @覆盖
    公共无效onDone(字符串utteranceId){
        如果(processStart){
            speech.startListening(意向);
        }其他{
            ...
        }    }    @覆盖
    公共无效onerror的(字符串utteranceId){
    }    @覆盖
    公共无效调用onStart(字符串utteranceId){
    }
}

我添加日志输出到所有我的TTS语音和方法。 UtteranceProgressListener的调用onStart甚至没有被称为:

  11-30 00:38:37.299:D / OpenGLRenderer(15842):启用调试模式0
11-30 00:38:39.782:I /文字转语音(15842):连接到ComponentInfo {com.google.android.tts / com.google.android.tts.service.GoogleTTSService}
11-30 00:38:39.782:I /文字转语音(15842):设置连接ComponentInfo {com.google.android.tts / com.google.android.tts.service.GoogleTTSService}
11-30 00:38:39.782:D /看我的!!!(15842):ttsInitListener - 的OnInit


解决方案

找到了答案......

原来,我在网上找到了使用单一TTS串源TTS资源,所以在tts.speak(字符串文字,诠释queueMode,HashMap的PARAMS)第三个参数被设置为null。

在未来有这个问题的人:

如果您设置的第三参数为空,没有ID为UtteranceProgressListener跟踪。整个解决方案创建和初始化一个HashMap,然后添加为一个新的ID每一个新的TTS包含的阵列可以被跟踪。这里的code:

 的HashMap<字符串,字符串>地图=新的HashMap<字符串,字符串>();

然后,调用tts.speak前...

  map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID的UniqueID);

然后你可以打电话说的所有参数...

  tts.speak(文字,TextToSpeech.QUEUE_FLUSH,地图);

I don't want to put all my code here, so I'm just putting the relevant pieces. If you need more, feel free to ask.

I'm using Text To Speech (TTS) which leads to a speech listener after it asks a question... I found through Log outputs that TTS's onInit is being called, but the UtteranceProgressListener is not and I can't figure out why. Any help is appreciated.

// ---Initialize TTS variables---

        // Implement Text to speech feature
        tts = new TextToSpeech(this, new ttsInitListener());

        // set listener to the TTS engine
        tts.setOnUtteranceProgressListener(new ttsUtteranceListener());

        if (!tts.isSpeaking()) {
            tts.speak("Speak to me", TextToSpeech.QUEUE_FLUSH, null);
        }


// --- TEXT TO SPEECH && SPEECH TO TEXT METHODS ---

class ttsInitListener implements OnInitListener {

    @Override
    public void onInit(int status) {

        if (status == TextToSpeech.SUCCESS) {
            tts.setLanguage(Locale.getDefault());

        } else {
            tts = null;
            Toast.makeText(mContext, "Failed to initialize TTS engine.",
                    Toast.LENGTH_SHORT).show();
        }
    }
}

class ttsUtteranceListener extends UtteranceProgressListener {

    @Override
    public void onDone(String utteranceId) {
        if (processStart) {
            speech.startListening(intent);
        } else {
            ...
        }

    }

    @Override
    public void onError(String utteranceId) {
    }

    @Override
    public void onStart(String utteranceId) {
    }    
}

I added log outputs to all of the my TTS and Speech methods. UtteranceProgressListener's onStart isn't even being called:

11-30 00:38:37.299: D/OpenGLRenderer(15842): Enabling debug mode 0
11-30 00:38:39.782: I/TextToSpeech(15842): Connected to ComponentInfo{com.google.android.tts/com.google.android.tts.service.GoogleTTSService}
11-30 00:38:39.782: I/TextToSpeech(15842): Set up connection to ComponentInfo{com.google.android.tts/com.google.android.tts.service.GoogleTTSService}
11-30 00:38:39.782: D/LOOK AT ME!!!(15842): ttsInitListener - onInit
解决方案

found the answer...

Turns out that the TTS resources I found online were using a single TTS string source, so the third parameter in tts.speak(String text, int queueMode, HashMap params) was set to null.

to anybody having this issue in the future:

if you set the third param to null, there's no ID for the UtteranceProgressListener to track. The fix was creating and initializing a hashmap, then adding to the included array for each new TTS with a new ID could be tracked. Here's the code:

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

then, before calling tts.speak...

map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "UniqueID");

then you can call speak with all params...

tts.speak(text, TextToSpeech.QUEUE_FLUSH, map);

这篇关于TTS-UtteranceProgressListener不会被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 01:04