|
|
@ -14,6 +14,7 @@ import io.legado.app.utils.FileUtils |
|
|
|
import io.legado.app.utils.LogUtils |
|
|
|
import io.legado.app.utils.LogUtils |
|
|
|
import io.legado.app.utils.MD5Utils |
|
|
|
import io.legado.app.utils.MD5Utils |
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
|
|
|
|
import kotlinx.coroutines.ensureActive |
|
|
|
import kotlinx.coroutines.isActive |
|
|
|
import kotlinx.coroutines.isActive |
|
|
|
import org.jetbrains.anko.collections.forEachWithIndex |
|
|
|
import org.jetbrains.anko.collections.forEachWithIndex |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
@ -103,18 +104,15 @@ class HttpReadAloudService : BaseReadAloudService(), |
|
|
|
speakText = item, |
|
|
|
speakText = item, |
|
|
|
speakSpeed = AppConfig.ttsSpeechRate |
|
|
|
speakSpeed = AppConfig.ttsSpeechRate |
|
|
|
).getByteArray().let { bytes -> |
|
|
|
).getByteArray().let { bytes -> |
|
|
|
if (isActive) { |
|
|
|
ensureActive() |
|
|
|
val file = getSpeakFileAsMd5(fileName) |
|
|
|
val file = getSpeakFileAsMd5(fileName) |
|
|
|
//val file = getSpeakFile(index) |
|
|
|
//val file = getSpeakFile(index) |
|
|
|
file.writeBytes(bytes) |
|
|
|
file.writeBytes(bytes) |
|
|
|
removeSpeakCacheFile(fileName) |
|
|
|
removeSpeakCacheFile(fileName) |
|
|
|
if (index == nowSpeak) { |
|
|
|
if (index == nowSpeak) { |
|
|
|
@Suppress("BlockingMethodInNonBlockingContext") |
|
|
|
@Suppress("BlockingMethodInNonBlockingContext") |
|
|
|
val fis = FileInputStream(file) |
|
|
|
val fis = FileInputStream(file) |
|
|
|
playAudio(fis.fd) |
|
|
|
playAudio(fis.fd) |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
removeSpeakCacheFile(fileName) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e: SocketTimeoutException) { |
|
|
|
} catch (e: SocketTimeoutException) { |
|
|
|