pull/42/head
kunfei 5 years ago
parent 613e68b75d
commit de46c6a1d5
  1. 4
      app/src/main/java/io/legado/app/data/api/IHttpPostApi.kt
  2. 11
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt

@ -45,9 +45,9 @@ interface IHttpPostApi {
@FormUrlEncoded
@POST
fun postMapByte(
fun postMapByteAsync(
@Url url: String,
@FieldMap(encoded = true) fieldMap: Map<String, String>,
@HeaderMap headers: Map<String, String>
): Call<ByteArray>
): Deferred<Response<ByteArray>>
}

@ -14,7 +14,6 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import org.jetbrains.anko.toast
import java.io.File
import java.io.FileDescriptor
import java.io.FileInputStream
@ -85,14 +84,12 @@ class HttpReadAloudService : BaseReadAloudService(),
if (isActive) {
val bytes = HttpHelper.getByteRetrofit("http://tts.baidu.com")
.create(IHttpPostApi::class.java)
.postMapByte(
.postMapByteAsync(
"http://tts.baidu.com/text2audio",
getAudioBody(contentList[index]), mapOf()
)
.execute().body()
if (bytes == null) {
toast("访问失败")
} else {
).await()
.body()
if (bytes != null && isActive) {
val file = getSpeakFile(index)
file.writeBytes(bytes)
if (index == nowSpeak) {

Loading…
Cancel
Save