pull/1343/head
gedoor 4 years ago
parent 60006e170a
commit 16ed77693c
  1. 16
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt

@ -86,16 +86,14 @@ class HttpReadAloudService : BaseReadAloudService(),
task?.cancel() task?.cancel()
task = execute { task = execute {
removeCacheFile() removeCacheFile()
ReadAloud.httpTTS?.let { ReadAloud.httpTTS?.let { httpTts ->
contentList.forEachIndexed { index, item -> contentList.forEachIndexed { index, item ->
if (isActive) { if (isActive) {
val fileName = val fileName =
md5SpeakFileName(it.url, AppConfig.ttsSpeechRate.toString(), item) md5SpeakFileName(httpTts.url, AppConfig.ttsSpeechRate.toString(), item)
if (hasSpeakFile(fileName)) { //已经下载好的语音缓存 if (hasSpeakFile(fileName)) { //已经下载好的语音缓存
if (index == nowSpeak) { if (index == nowSpeak) {
val file = getSpeakFileAsMd5(fileName) val file = getSpeakFileAsMd5(fileName)
@Suppress("BlockingMethodInNonBlockingContext")
val fis = FileInputStream(file) val fis = FileInputStream(file)
playAudio(fis.fd) playAudio(fis.fd)
} }
@ -105,19 +103,17 @@ class HttpReadAloudService : BaseReadAloudService(),
try { try {
createSpeakCacheFile(fileName) createSpeakCacheFile(fileName)
AnalyzeUrl( AnalyzeUrl(
it.url, httpTts.url,
speakText = item, speakText = item,
speakSpeed = AppConfig.ttsSpeechRate speakSpeed = AppConfig.ttsSpeechRate,
source = httpTts,
headerMapF = httpTts.getHeaderMap(true)
).getByteArray().let { bytes -> ).getByteArray().let { bytes ->
ensureActive() ensureActive()
val file = getSpeakFileAsMd5IfNotExist(fileName) val file = getSpeakFileAsMd5IfNotExist(fileName)
//val file = getSpeakFile(index)
file.writeBytes(bytes) file.writeBytes(bytes)
removeSpeakCacheFile(fileName) removeSpeakCacheFile(fileName)
val fis = FileInputStream(file) val fis = FileInputStream(file)
if (index == nowSpeak) { if (index == nowSpeak) {
@Suppress("BlockingMethodInNonBlockingContext") @Suppress("BlockingMethodInNonBlockingContext")
playAudio(fis.fd) playAudio(fis.fd)

Loading…
Cancel
Save