|
|
@ -12,6 +12,7 @@ import io.legado.app.utils.getPrefString |
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
import io.legado.app.utils.postEvent |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Dispatchers.IO |
|
|
|
import kotlinx.coroutines.Job |
|
|
|
import kotlinx.coroutines.Job |
|
|
|
|
|
|
|
import kotlinx.coroutines.isActive |
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import org.jetbrains.anko.toast |
|
|
|
import java.io.File |
|
|
|
import java.io.File |
|
|
@ -81,20 +82,22 @@ class HttpReadAloudService : BaseReadAloudService(), |
|
|
|
job = launch(IO) { |
|
|
|
job = launch(IO) { |
|
|
|
FileHelp.deleteFile(ttsFolder) |
|
|
|
FileHelp.deleteFile(ttsFolder) |
|
|
|
for (index in 0 until contentList.size) { |
|
|
|
for (index in 0 until contentList.size) { |
|
|
|
val bytes = HttpHelper.getByteRetrofit("http://tts.baidu.com") |
|
|
|
if (isActive) { |
|
|
|
.create(IHttpPostApi::class.java) |
|
|
|
val bytes = HttpHelper.getByteRetrofit("http://tts.baidu.com") |
|
|
|
.postMapByte( |
|
|
|
.create(IHttpPostApi::class.java) |
|
|
|
"http://tts.baidu.com/text2audio", |
|
|
|
.postMapByte( |
|
|
|
getAudioBody(contentList[index]), mapOf() |
|
|
|
"http://tts.baidu.com/text2audio", |
|
|
|
) |
|
|
|
getAudioBody(contentList[index]), mapOf() |
|
|
|
.execute().body() |
|
|
|
) |
|
|
|
if (bytes == null) { |
|
|
|
.execute().body() |
|
|
|
toast("访问失败") |
|
|
|
if (bytes == null) { |
|
|
|
} else { |
|
|
|
toast("访问失败") |
|
|
|
val file = getSpeakFile(index) |
|
|
|
} else { |
|
|
|
file.writeBytes(bytes) |
|
|
|
val file = getSpeakFile(index) |
|
|
|
if (index == nowSpeak) { |
|
|
|
file.writeBytes(bytes) |
|
|
|
playAudio(FileInputStream(file).fd) |
|
|
|
if (index == nowSpeak) { |
|
|
|
|
|
|
|
playAudio(FileInputStream(file).fd) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|