pull/71/head
kunfei 5 years ago
parent 797c6eb9c8
commit ec1d335c57
  1. 4
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  2. 53
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt

@ -122,7 +122,9 @@ class ReadRssActivity : VMBaseActivity<ReadRssViewModel>(R.layout.activity_rss_r
}
private fun readAloud() {
webView.evaluateJavascript("document.documentElement.outerHTML") {
viewModel.readAloud(it)
}
}
}

@ -2,21 +2,28 @@ package io.legado.app.ui.rss.read
import android.app.Application
import android.content.Intent
import android.speech.tts.TextToSpeech
import android.speech.tts.UtteranceProgressListener
import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssSource
import io.legado.app.model.Rss
import io.legado.app.model.analyzeRule.AnalyzeUrl
import kotlinx.coroutines.launch
import java.util.*
class ReadRssViewModel(application: Application) : BaseViewModel(application) {
class ReadRssViewModel(application: Application) : BaseViewModel(application),
TextToSpeech.OnInitListener {
var callBack: CallBack? = null
var rssSource: RssSource? = null
var rssArticle: RssArticle? = null
val contentLiveData = MutableLiveData<String>()
val urlLiveData = MutableLiveData<AnalyzeUrl>()
var star = false
var textToSpeech: TextToSpeech = TextToSpeech(context, this)
fun initData(intent: Intent) {
execute {
@ -91,6 +98,50 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
}
}
override fun onInit(status: Int) {
launch {
if (status == TextToSpeech.SUCCESS) {
textToSpeech.language = Locale.CHINA
textToSpeech.setOnUtteranceProgressListener(TTSUtteranceListener())
} else {
toast(R.string.tts_init_failed)
}
}
}
fun readAloud(text: String) {
}
override fun onCleared() {
super.onCleared()
textToSpeech.stop()
textToSpeech.shutdown()
}
/**
* 朗读监听
*/
private inner class TTSUtteranceListener : UtteranceProgressListener() {
override fun onStart(s: String) {
}
override fun onDone(s: String) {
}
override fun onRangeStart(utteranceId: String?, start: Int, end: Int, frame: Int) {
super.onRangeStart(utteranceId, start, end, frame)
}
override fun onError(s: String) {
}
}
interface CallBack {
fun upStarMenu()
}

Loading…
Cancel
Save