onUtteranceCompleted() lost if TTS received is too long

Deadly 提交于 2019-12-08 19:16:28

问题


I just observed an "undocumented anomaly" in Android's TTS engine: If the text to be spoken is too long (greater than 4K characters), then onUtteranceCompleted() for that particular utterance will never arrive...

Has anyone else come across this?

Is this a known bug or limitation?

What could be done to work around this?


回答1:


I wasn't aware of the limit, as I prefer smaller chunks of speech (useful if pausing or if activity is paused).

When you call speak, you can add the new utterance to the end of the queue using this for queueMode: TextToSpeech.QUEUE_ADD

Test to be sure the sentence doesn't sound different, but I think just automatically parsing at the next sentence (or word if needed) after a cutoff length would work.




回答2:


I am not sure if this will be helpful in your case, but in a similar situation I used an anonymous broadcast reciever with an IntentFilter for TextToSpeech.ACTION_TTS_QUEUE_PROCESSING_COMPLETED as given below

  filter = new IntentFilter(TextToSpeech.ACTION_TTS_QUEUE_PROCESSING_COMPLETED);
receiver = new BroadcastReceiver(){

        public void onReceive(Context p1, Intent p2)
        {
            if (p2.getAction().equals(TextToSpeech.ACTION_TTS_QUEUE_PROCESSING_COMPLETED) && tts != null)
            {
            //
                //code here
            }
        }
    };
context.registerReceiver(receiver, filter);
    tts = new TextToSpeech(context, this);

Hope this could be of some help for someone at sometime



来源:https://stackoverflow.com/questions/6863107/onutterancecompleted-lost-if-tts-received-is-too-long

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!