fix-empty-tts-text (#4199)
This commit is contained in:
@@ -93,8 +93,18 @@ 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 {
|
for (i in nowSpeak until contentList.size) {
|
||||||
speak("", TextToSpeech.QUEUE_FLUSH, null, null)
|
var text = contentList[i]
|
||||||
|
ensureActive()
|
||||||
|
if (paragraphStartPos > 0 && i == nowSpeak) {
|
||||||
|
text = text.substring(paragraphStartPos)
|
||||||
|
}
|
||||||
|
if (text.matches(AppPattern.notReadAloudRegex)) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (i == nowSpeak) {
|
||||||
|
val result = tts.runCatching {
|
||||||
|
speak(text, TextToSpeech.QUEUE_FLUSH, null, AppConst.APP_TAG + i)
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
AppLog.put("tts出错\n${it.localizedMessage}", it, true)
|
AppLog.put("tts出错\n${it.localizedMessage}", it, true)
|
||||||
TextToSpeech.ERROR
|
TextToSpeech.ERROR
|
||||||
@@ -105,17 +115,8 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
|
|||||||
initTts()
|
initTts()
|
||||||
return@execute
|
return@execute
|
||||||
}
|
}
|
||||||
val contentList = contentList
|
} else {
|
||||||
for (i in nowSpeak until contentList.size) {
|
val result = tts.runCatching {
|
||||||
ensureActive()
|
|
||||||
var text = contentList[i]
|
|
||||||
if (paragraphStartPos > 0 && i == nowSpeak) {
|
|
||||||
text = text.substring(paragraphStartPos)
|
|
||||||
}
|
|
||||||
if (text.matches(AppPattern.notReadAloudRegex)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
result = tts.runCatching {
|
|
||||||
speak(text, TextToSpeech.QUEUE_ADD, null, AppConst.APP_TAG + i)
|
speak(text, TextToSpeech.QUEUE_ADD, null, AppConst.APP_TAG + i)
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
AppLog.put("tts出错\n${it.localizedMessage}", it, true)
|
AppLog.put("tts出错\n${it.localizedMessage}", it, true)
|
||||||
@@ -125,6 +126,9 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
|
|||||||
AppLog.put("tts朗读出错:$text")
|
AppLog.put("tts朗读出错:$text")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
LogUtils.d(TAG, "朗读内容添加完成")
|
LogUtils.d(TAG, "朗读内容添加完成")
|
||||||
}.onError {
|
}.onError {
|
||||||
AppLog.put("tts朗读出错\n${it.localizedMessage}", it, true)
|
AppLog.put("tts朗读出错\n${it.localizedMessage}", it, true)
|
||||||
|
|||||||
Reference in New Issue
Block a user