pull/1738/head
kunfei 3 years ago
parent f6c061b5ad
commit 0c50b867ad
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 12
      app/src/main/java/io/legado/app/help/config/AppConfig.kt
  3. 6
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  4. 5
      app/src/main/java/io/legado/app/service/TTSReadAloudService.kt
  5. 3
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt

@ -27,6 +27,7 @@ object PreferKey {
const val precisionSearch = "precisionSearch"
const val readAloudByPage = "readAloudByPage"
const val ttsEngine = "appTtsEngine"
const val ttsFollowSys = "ttsFollowSys"
const val ttsSpeechRate = "ttsSpeechRate"
const val prevKeys = "prevKeyCodes"
const val nextKeys = "nextKeyCodes"

@ -169,12 +169,22 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener {
}
}
var ttsFlowSys: Boolean
get() = appCtx.getPrefBoolean(PreferKey.ttsFollowSys, true)
set(value) {
appCtx.putPrefBoolean(PreferKey.ttsFollowSys, value)
}
const val defaultSpeechRate = 5
var ttsSpeechRate: Int
get() = appCtx.getPrefInt(PreferKey.ttsSpeechRate, 5)
get() = appCtx.getPrefInt(PreferKey.ttsSpeechRate, defaultSpeechRate)
set(value) {
appCtx.putPrefInt(PreferKey.ttsSpeechRate, value)
}
val speechRatePlay: Int get() = if (ttsFlowSys) defaultSpeechRate else ttsSpeechRate
var chineseConverterType: Int
get() = appCtx.getPrefInt(PreferKey.chineseConverterType)
set(value) {

@ -41,6 +41,7 @@ class HttpReadAloudService : BaseReadAloudService(),
private val ttsFolderPath: String by lazy {
cacheDir.absolutePath + File.separator + "httpTTS" + File.separator
}
private var speechRate: Int = AppConfig.speechRatePlay
private val cacheFiles = hashSetOf<String>()
private var task: Coroutine<*>? = null
private var playIndexJob: Job? = null
@ -113,7 +114,7 @@ class HttpReadAloudService : BaseReadAloudService(),
contentList.forEachIndexed { index, content ->
ensureActive()
val fileName =
md5SpeakFileName(httpTts.url, AppConfig.ttsSpeechRate.toString(), content)
md5SpeakFileName(httpTts.url, speechRate.toString(), content)
val speakText = content.replace(AppPattern.notReadAloudRegex, "")
if (hasSpeakFile(fileName)) { //已经下载好的语音缓存
if (index == nowSpeak) {
@ -131,7 +132,7 @@ class HttpReadAloudService : BaseReadAloudService(),
val analyzeUrl = AnalyzeUrl(
httpTts.url,
speakText = speakText,
speakSpeed = AppConfig.ttsSpeechRate,
speakSpeed = speechRate,
source = httpTts,
headerMapF = httpTts.getHeaderMap(true)
)
@ -317,6 +318,7 @@ class HttpReadAloudService : BaseReadAloudService(),
override fun upSpeechRate(reset: Boolean) {
task?.cancel()
exoPlayer.stop()
speechRate = AppConfig.speechRatePlay
downloadAudio()
}

@ -106,13 +106,14 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
* 更新朗读速度
*/
override fun upSpeechRate(reset: Boolean) {
if (this.getPrefBoolean("ttsFollowSys", true)) {
if (AppConfig.ttsFlowSys) {
if (reset) {
clearTTS()
initTts()
}
} else {
textToSpeech?.setSpeechRate((AppConfig.ttsSpeechRate + 5) / 10f)
val speechRate = (AppConfig.ttsSpeechRate + 5) / 10f
textToSpeech?.setSpeechRate(speechRate)
}
}

@ -22,7 +22,6 @@ import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.getPrefBoolean
import io.legado.app.utils.observeEvent
import io.legado.app.utils.putPrefBoolean
import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -110,7 +109,7 @@ class ReadAloudDialog : BaseDialogFragment(R.layout.dialog_read_aloud) {
llCatalog.setOnClickListener { callBack?.openChapterList() }
llToBackstage.setOnClickListener { callBack?.finish() }
cbTtsFollowSys.setOnCheckedChangeListener { _, isChecked ->
requireContext().putPrefBoolean("ttsFollowSys", isChecked)
AppConfig.ttsFlowSys = isChecked
seekTtsSpeechRate.isEnabled = !isChecked
upTtsSpeechRate()
}

Loading…
Cancel
Save