|
|
@ -2,6 +2,7 @@ package io.legado.app.service |
|
|
|
|
|
|
|
|
|
|
|
import android.app.PendingIntent |
|
|
|
import android.app.PendingIntent |
|
|
|
import android.media.MediaPlayer |
|
|
|
import android.media.MediaPlayer |
|
|
|
|
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.constant.AppLog |
|
|
|
import io.legado.app.constant.AppLog |
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
import io.legado.app.constant.EventBus |
|
|
|
import io.legado.app.help.AppConfig |
|
|
|
import io.legado.app.help.AppConfig |
|
|
@ -112,7 +113,7 @@ class HttpReadAloudService : BaseReadAloudService(), |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (speakText.isEmpty()) { |
|
|
|
if (speakText.isEmpty()) { |
|
|
|
ensureActive() |
|
|
|
ensureActive() |
|
|
|
createSpeakFileAsMd5IfNotExist(fileName) |
|
|
|
createSilentSound(fileName) |
|
|
|
return@let |
|
|
|
return@let |
|
|
|
} |
|
|
|
} |
|
|
|
createSpeakCacheFile(fileName) |
|
|
|
createSpeakCacheFile(fileName) |
|
|
@ -143,19 +144,24 @@ class HttpReadAloudService : BaseReadAloudService(), |
|
|
|
//任务取消,不处理 |
|
|
|
//任务取消,不处理 |
|
|
|
} catch (e: SocketTimeoutException) { |
|
|
|
} catch (e: SocketTimeoutException) { |
|
|
|
removeSpeakCacheFile(fileName) |
|
|
|
removeSpeakCacheFile(fileName) |
|
|
|
|
|
|
|
errorNo++ |
|
|
|
|
|
|
|
if (errorNo > 5) { |
|
|
|
|
|
|
|
createSilentSound(fileName) |
|
|
|
|
|
|
|
} else { |
|
|
|
toastOnUi("tts接口超时,尝试重新获取") |
|
|
|
toastOnUi("tts接口超时,尝试重新获取") |
|
|
|
downloadAudio() |
|
|
|
downloadAudio() |
|
|
|
|
|
|
|
} |
|
|
|
} catch (e: ConnectException) { |
|
|
|
} catch (e: ConnectException) { |
|
|
|
removeSpeakCacheFile(fileName) |
|
|
|
removeSpeakCacheFile(fileName) |
|
|
|
toastOnUi("tts接口网络错误\n${e.localizedMessage}") |
|
|
|
toastOnUi("tts接口网络错误\n${e.localizedMessage}") |
|
|
|
} catch (e: IOException) { |
|
|
|
} catch (e: IOException) { |
|
|
|
removeSpeakCacheFile(fileName) |
|
|
|
removeSpeakCacheFile(fileName) |
|
|
|
createSpeakFileAsMd5IfNotExist(fileName) |
|
|
|
createSilentSound(fileName) |
|
|
|
AppLog.put("tts文件解析错误") |
|
|
|
AppLog.put("tts文件解析错误") |
|
|
|
toastOnUi("tts文件解析错误\n${e.localizedMessage}") |
|
|
|
toastOnUi("tts文件解析错误\n${e.localizedMessage}") |
|
|
|
} catch (e: Exception) { |
|
|
|
} catch (e: Exception) { |
|
|
|
removeSpeakCacheFile(fileName) |
|
|
|
removeSpeakCacheFile(fileName) |
|
|
|
createSpeakFileAsMd5IfNotExist(fileName) |
|
|
|
createSilentSound(fileName) |
|
|
|
AppLog.put("tts接口错误\n${e.localizedMessage}", e) |
|
|
|
AppLog.put("tts接口错误\n${e.localizedMessage}", e) |
|
|
|
toastOnUi("tts接口错误\n${e.localizedMessage}") |
|
|
|
toastOnUi("tts接口错误\n${e.localizedMessage}") |
|
|
|
e.printOnDebug() |
|
|
|
e.printOnDebug() |
|
|
@ -187,6 +193,11 @@ class HttpReadAloudService : BaseReadAloudService(), |
|
|
|
return MD5Utils.md5Encode16(textChapter!!.title) + "_" + MD5Utils.md5Encode16("$url-|-$ttsConfig-|-$content") |
|
|
|
return MD5Utils.md5Encode16(textChapter!!.title) + "_" + MD5Utils.md5Encode16("$url-|-$ttsConfig-|-$content") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun createSilentSound(fileName: String) { |
|
|
|
|
|
|
|
val file = createSpeakFileAsMd5IfNotExist(fileName) |
|
|
|
|
|
|
|
file.writeBytes(resources.openRawResource(R.raw.silent_sound).readBytes()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun hasSpeakFile(name: String) = |
|
|
|
private fun hasSpeakFile(name: String) = |
|
|
|
FileUtils.exist("${speakFilePath()}$name.mp3") |
|
|
|
FileUtils.exist("${speakFilePath()}$name.mp3") |
|
|
|
|
|
|
|
|
|
|
|