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 @FormUrlEncoded
@POST @POST
fun postMapByte( fun postMapByteAsync(
@Url url: String, @Url url: String,
@FieldMap(encoded = true) fieldMap: Map<String, String>, @FieldMap(encoded = true) fieldMap: Map<String, String>,
@HeaderMap headers: 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.Job
import kotlinx.coroutines.isActive import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.toast
import java.io.File import java.io.File
import java.io.FileDescriptor import java.io.FileDescriptor
import java.io.FileInputStream import java.io.FileInputStream
@ -85,14 +84,12 @@ class HttpReadAloudService : BaseReadAloudService(),
if (isActive) { if (isActive) {
val bytes = HttpHelper.getByteRetrofit("http://tts.baidu.com") val bytes = HttpHelper.getByteRetrofit("http://tts.baidu.com")
.create(IHttpPostApi::class.java) .create(IHttpPostApi::class.java)
.postMapByte( .postMapByteAsync(
"http://tts.baidu.com/text2audio", "http://tts.baidu.com/text2audio",
getAudioBody(contentList[index]), mapOf() getAudioBody(contentList[index]), mapOf()
) ).await()
.execute().body() .body()
if (bytes == null) { if (bytes != null && isActive) {
toast("访问失败")
} else {
val file = getSpeakFile(index) val file = getSpeakFile(index)
file.writeBytes(bytes) file.writeBytes(bytes)
if (index == nowSpeak) { if (index == nowSpeak) {

Loading…
Cancel
Save