我使用 TextToSpeech
有时会打一些长文,我已经注意到,由于安卓4.1.2
如果文本的长度超过4000个字符,不玩了。
我没有得到任何错误,但文字不会被播放。到现在为止,我能够重现这只是安卓4.1.2
(三星Galaxy Nexus的,Nexus7)。
这是只是在一个错误 4.1.2
或这是正常的(虽然我没有找到有关此问题的任何文件)?
此外,我找到了一个帖子:onUtteranceCompleted()如果TTS收到过长这说明不同的问题与文本超过4000个字符再丢失。
编辑:我试图用来分割我的字符串在4K长块,并将其发送到
和我遇到另一个bug: TTS
QUEUE_ADD QUEUE_ADD
不工作,而是刷新现有的队列中,只有最后一块被打了。
EDIT2 :这是我的电话,以 TTS
mTTS.speak(LONGTEXT,TextToSpeech.QUEUE_FLUSH,NULL);
解决方案
MAX_SPEECH_ITEM_CHAR_LENGTH = 4000 TtsService.java,对4.1我看到一个警告,在code:
@覆盖
公共布尔参考isValid(){
如果(MTEXT == NULL){
Log.wtf(TAG,得到空文);
返回false;
}
如果(mText.length()> = MAX_SPEECH_ITEM_CHAR_LENGTH){
Log.w(TAG,文本太长:+ mText.length()+字符);
返回false;
}
返回true;
}
看起来像2.3分裂的文字来代替,所以teorically您code应该工作在Android< 4.1,而不是新的(除去拆分的时候,我不知道),而不是你有相反的:)这是一个有点奇怪
I am using TextToSpeech
to play some long texts sometimes, and I have noticed that since Android 4.1.2
if the text is longer than 4000 chars, it does not play.
I do not get any errors, but the text won't be played. Until now I was able to reproduce this just on Android 4.1.2
(Samsung Galaxy Nexus, Nexus7).
Is this a bug just in 4.1.2
or is this normal (although I did not find any documentation regarding this behaviour)?
Also I have found a post : onUtteranceCompleted() lost if TTS received is too long which indicates different problems with texts longer than 4000 chars.
EDIT: I tried to split my string in 4k length chunks, and send it to TTS
using QUEUE_ADD
and I came across another bug: QUEUE_ADD
does not work, instead it flushes the existing queue, and only the last chunk gets played.
EDIT2 : this is my call to TTS
mTTS.speak(longText, TextToSpeech.QUEUE_FLUSH, null);
解决方案
MAX_SPEECH_ITEM_CHAR_LENGTH = 4000 in TtsService.java, on 4.1 I see a warn in the code:
@Override
public boolean isValid() {
if (mText == null) {
Log.wtf(TAG, "Got null text");
return false;
}
if (mText.length() >= MAX_SPEECH_ITEM_CHAR_LENGTH) {
Log.w(TAG, "Text too long: " + mText.length() + " chars");
return false;
}
return true;
}
looks like 2.3 splits the text instead, so teorically your code should work on android < 4.1 and not on newer (I don't known when the split was removed), instead you have the opposite :) that is a bit strange