优化
This commit is contained in:
@@ -27,6 +27,7 @@ object PreferKey {
|
|||||||
const val precisionSearch = "precisionSearch"
|
const val precisionSearch = "precisionSearch"
|
||||||
const val readAloudByPage = "readAloudByPage"
|
const val readAloudByPage = "readAloudByPage"
|
||||||
const val ttsEngine = "appTtsEngine"
|
const val ttsEngine = "appTtsEngine"
|
||||||
|
const val ttsFollowSys = "ttsFollowSys"
|
||||||
const val ttsSpeechRate = "ttsSpeechRate"
|
const val ttsSpeechRate = "ttsSpeechRate"
|
||||||
const val prevKeys = "prevKeyCodes"
|
const val prevKeys = "prevKeyCodes"
|
||||||
const val nextKeys = "nextKeyCodes"
|
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
|
var ttsSpeechRate: Int
|
||||||
get() = appCtx.getPrefInt(PreferKey.ttsSpeechRate, 5)
|
get() = appCtx.getPrefInt(PreferKey.ttsSpeechRate, defaultSpeechRate)
|
||||||
set(value) {
|
set(value) {
|
||||||
appCtx.putPrefInt(PreferKey.ttsSpeechRate, value)
|
appCtx.putPrefInt(PreferKey.ttsSpeechRate, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val speechRatePlay: Int get() = if (ttsFlowSys) defaultSpeechRate else ttsSpeechRate
|
||||||
|
|
||||||
var chineseConverterType: Int
|
var chineseConverterType: Int
|
||||||
get() = appCtx.getPrefInt(PreferKey.chineseConverterType)
|
get() = appCtx.getPrefInt(PreferKey.chineseConverterType)
|
||||||
set(value) {
|
set(value) {
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ class HttpReadAloudService : BaseReadAloudService(),
|
|||||||
private val ttsFolderPath: String by lazy {
|
private val ttsFolderPath: String by lazy {
|
||||||
cacheDir.absolutePath + File.separator + "httpTTS" + File.separator
|
cacheDir.absolutePath + File.separator + "httpTTS" + File.separator
|
||||||
}
|
}
|
||||||
|
private var speechRate: Int = AppConfig.speechRatePlay
|
||||||
private val cacheFiles = hashSetOf<String>()
|
private val cacheFiles = hashSetOf<String>()
|
||||||
private var task: Coroutine<*>? = null
|
private var task: Coroutine<*>? = null
|
||||||
private var playIndexJob: Job? = null
|
private var playIndexJob: Job? = null
|
||||||
@@ -113,7 +114,7 @@ class HttpReadAloudService : BaseReadAloudService(),
|
|||||||
contentList.forEachIndexed { index, content ->
|
contentList.forEachIndexed { index, content ->
|
||||||
ensureActive()
|
ensureActive()
|
||||||
val fileName =
|
val fileName =
|
||||||
md5SpeakFileName(httpTts.url, AppConfig.ttsSpeechRate.toString(), content)
|
md5SpeakFileName(httpTts.url, speechRate.toString(), content)
|
||||||
val speakText = content.replace(AppPattern.notReadAloudRegex, "")
|
val speakText = content.replace(AppPattern.notReadAloudRegex, "")
|
||||||
if (hasSpeakFile(fileName)) { //已经下载好的语音缓存
|
if (hasSpeakFile(fileName)) { //已经下载好的语音缓存
|
||||||
if (index == nowSpeak) {
|
if (index == nowSpeak) {
|
||||||
@@ -131,7 +132,7 @@ class HttpReadAloudService : BaseReadAloudService(),
|
|||||||
val analyzeUrl = AnalyzeUrl(
|
val analyzeUrl = AnalyzeUrl(
|
||||||
httpTts.url,
|
httpTts.url,
|
||||||
speakText = speakText,
|
speakText = speakText,
|
||||||
speakSpeed = AppConfig.ttsSpeechRate,
|
speakSpeed = speechRate,
|
||||||
source = httpTts,
|
source = httpTts,
|
||||||
headerMapF = httpTts.getHeaderMap(true)
|
headerMapF = httpTts.getHeaderMap(true)
|
||||||
)
|
)
|
||||||
@@ -317,6 +318,7 @@ class HttpReadAloudService : BaseReadAloudService(),
|
|||||||
override fun upSpeechRate(reset: Boolean) {
|
override fun upSpeechRate(reset: Boolean) {
|
||||||
task?.cancel()
|
task?.cancel()
|
||||||
exoPlayer.stop()
|
exoPlayer.stop()
|
||||||
|
speechRate = AppConfig.speechRatePlay
|
||||||
downloadAudio()
|
downloadAudio()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,13 +106,14 @@ class TTSReadAloudService : BaseReadAloudService(), TextToSpeech.OnInitListener
|
|||||||
* 更新朗读速度
|
* 更新朗读速度
|
||||||
*/
|
*/
|
||||||
override fun upSpeechRate(reset: Boolean) {
|
override fun upSpeechRate(reset: Boolean) {
|
||||||
if (this.getPrefBoolean("ttsFollowSys", true)) {
|
if (AppConfig.ttsFlowSys) {
|
||||||
if (reset) {
|
if (reset) {
|
||||||
clearTTS()
|
clearTTS()
|
||||||
initTts()
|
initTts()
|
||||||
}
|
}
|
||||||
} else {
|
} 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.ColorUtils
|
||||||
import io.legado.app.utils.getPrefBoolean
|
import io.legado.app.utils.getPrefBoolean
|
||||||
import io.legado.app.utils.observeEvent
|
import io.legado.app.utils.observeEvent
|
||||||
import io.legado.app.utils.putPrefBoolean
|
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
|
||||||
|
|
||||||
@@ -110,7 +109,7 @@ class ReadAloudDialog : BaseDialogFragment(R.layout.dialog_read_aloud) {
|
|||||||
llCatalog.setOnClickListener { callBack?.openChapterList() }
|
llCatalog.setOnClickListener { callBack?.openChapterList() }
|
||||||
llToBackstage.setOnClickListener { callBack?.finish() }
|
llToBackstage.setOnClickListener { callBack?.finish() }
|
||||||
cbTtsFollowSys.setOnCheckedChangeListener { _, isChecked ->
|
cbTtsFollowSys.setOnCheckedChangeListener { _, isChecked ->
|
||||||
requireContext().putPrefBoolean("ttsFollowSys", isChecked)
|
AppConfig.ttsFlowSys = isChecked
|
||||||
seekTtsSpeechRate.isEnabled = !isChecked
|
seekTtsSpeechRate.isEnabled = !isChecked
|
||||||
upTtsSpeechRate()
|
upTtsSpeechRate()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user