fix-empty-tts-text (#4199)
This commit is contained in:
@@ -93,37 +93,41 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
|
|||||||
LogUtils.d(TAG, "朗读列表大小 ${contentList.size}")
|
LogUtils.d(TAG, "朗读列表大小 ${contentList.size}")
|
||||||
LogUtils.d(TAG, "朗读页数 ${textChapter?.pageSize}")
|
LogUtils.d(TAG, "朗读页数 ${textChapter?.pageSize}")
|
||||||
val tts = textToSpeech ?: throw NoStackTraceException("tts is null")
|
val tts = textToSpeech ?: throw NoStackTraceException("tts is null")
|
||||||
var result = tts.runCatching {
|
|
||||||
speak("", TextToSpeech.QUEUE_FLUSH, null, null)
|
|
||||||
}.getOrElse {
|
|
||||||
AppLog.put("tts出错\n${it.localizedMessage}", it, true)
|
|
||||||
TextToSpeech.ERROR
|
|
||||||
}
|
|
||||||
if (result == TextToSpeech.ERROR) {
|
|
||||||
AppLog.put("tts出错 尝试重新初始化")
|
|
||||||
clearTTS()
|
|
||||||
initTts()
|
|
||||||
return@execute
|
|
||||||
}
|
|
||||||
val contentList = contentList
|
|
||||||
for (i in nowSpeak until contentList.size) {
|
for (i in nowSpeak until contentList.size) {
|
||||||
ensureActive()
|
|
||||||
var text = contentList[i]
|
var text = contentList[i]
|
||||||
|
ensureActive()
|
||||||
if (paragraphStartPos > 0 && i == nowSpeak) {
|
if (paragraphStartPos > 0 && i == nowSpeak) {
|
||||||
text = text.substring(paragraphStartPos)
|
text = text.substring(paragraphStartPos)
|
||||||
}
|
}
|
||||||
if (text.matches(AppPattern.notReadAloudRegex)) {
|
if (text.matches(AppPattern.notReadAloudRegex)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result = tts.runCatching {
|
if (i == nowSpeak) {
|
||||||
speak(text, TextToSpeech.QUEUE_ADD, null, AppConst.APP_TAG + i)
|
val result = tts.runCatching {
|
||||||
}.getOrElse {
|
speak(text, TextToSpeech.QUEUE_FLUSH, null, AppConst.APP_TAG + i)
|
||||||
AppLog.put("tts出错\n${it.localizedMessage}", it, true)
|
}.getOrElse {
|
||||||
TextToSpeech.ERROR
|
AppLog.put("tts出错\n${it.localizedMessage}", it, true)
|
||||||
}
|
TextToSpeech.ERROR
|
||||||
if (result == TextToSpeech.ERROR) {
|
}
|
||||||
AppLog.put("tts朗读出错:$text")
|
if (result == TextToSpeech.ERROR) {
|
||||||
|
AppLog.put("tts出错 尝试重新初始化")
|
||||||
|
clearTTS()
|
||||||
|
initTts()
|
||||||
|
return@execute
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val result = tts.runCatching {
|
||||||
|
speak(text, TextToSpeech.QUEUE_ADD, null, AppConst.APP_TAG + i)
|
||||||
|
}.getOrElse {
|
||||||
|
AppLog.put("tts出错\n${it.localizedMessage}", it, true)
|
||||||
|
TextToSpeech.ERROR
|
||||||
|
}
|
||||||
|
if (result == TextToSpeech.ERROR) {
|
||||||
|
AppLog.put("tts朗读出错:$text")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
LogUtils.d(TAG, "朗读内容添加完成")
|
LogUtils.d(TAG, "朗读内容添加完成")
|
||||||
}.onError {
|
}.onError {
|
||||||
|
|||||||
Reference in New Issue
Block a user