pull/34/head
kunfei 5 years ago
parent 0ca3931b18
commit fe10c289e9
  1. 5
      app/src/main/java/io/legado/app/service/HttpReadAloudService.kt
  2. 31
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudConfigDialog.kt
  3. 1
      app/src/main/res/xml/pref_config_aloud.xml

@ -6,6 +6,7 @@ import android.content.Intent
import android.media.MediaPlayer import android.media.MediaPlayer
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.utils.getPrefInt import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getPrefString
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
@ -31,8 +32,8 @@ class HttpReadAloudService : BaseReadAloudService(),
private fun getAudioPath(): String { private fun getAudioPath(): String {
val audioText = contentList[nowSpeak] val audioText = contentList[nowSpeak]
val spd = getPrefInt("ttsSpeechRate", 5) + 5 val spd = (getPrefInt("ttsSpeechRate", 25) + 5) / 5
val per = getPrefInt("ttsSpeechPer") val per = getPrefString("ttsSpeechPer") ?: "0"
return "http://tts.baidu.com/text2audio?idx=1&tex=$audioText&cuid=baidu_speech_demo&cod=2&lan=zh&ctp=1&pdt=1&spd=$spd&per=$per&vol=5&pit=5&_res_tag_=audio" return "http://tts.baidu.com/text2audio?idx=1&tex=$audioText&cuid=baidu_speech_demo&cod=2&lan=zh&ctp=1&pdt=1&spd=$spd&per=$per&vol=5&pit=5&_res_tag_=audio"
} }

@ -8,6 +8,8 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
@ -15,6 +17,7 @@ import io.legado.app.help.ReadAloud
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.service.BaseReadAloudService import io.legado.app.service.BaseReadAloudService
import io.legado.app.ui.readbook.Help import io.legado.app.ui.readbook.Help
import io.legado.app.utils.getPrefString
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
class ReadAloudConfigDialog : DialogFragment() { class ReadAloudConfigDialog : DialogFragment() {
@ -55,7 +58,8 @@ class ReadAloudConfigDialog : DialogFragment() {
} }
class ReadAloudPreferenceFragment : PreferenceFragmentCompat(), class ReadAloudPreferenceFragment : PreferenceFragmentCompat(),
SharedPreferences.OnSharedPreferenceChangeListener { SharedPreferences.OnSharedPreferenceChangeListener,
Preference.OnPreferenceChangeListener {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_aloud) addPreferencesFromResource(R.xml.pref_config_aloud)
@ -64,6 +68,7 @@ class ReadAloudConfigDialog : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
ATH.applyEdgeEffectColor(listView) ATH.applyEdgeEffectColor(listView)
bindPreferenceSummaryToValue(findPreference("ttsSpeechPer"))
} }
override fun onResume() { override fun onResume() {
@ -93,5 +98,29 @@ class ReadAloudConfigDialog : DialogFragment() {
} }
} }
override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean {
val stringValue = newValue.toString()
if (preference is ListPreference) {
val index = preference.findIndexOfValue(stringValue)
// Set the summary to reflect the new value.
preference.setSummary(if (index >= 0) preference.entries[index] else null)
} else {
// For all other preferences, set the summary to the value's
preference?.summary = stringValue
}
return true
}
private fun bindPreferenceSummaryToValue(preference: Preference?) {
preference?.apply {
onPreferenceChangeListener = this@ReadAloudPreferenceFragment
onPreferenceChange(
this,
context.getPrefString(key)
)
}
}
} }
} }

@ -17,6 +17,7 @@
<androidx.preference.ListPreference <androidx.preference.ListPreference
android:key="ttsSpeechPer" android:key="ttsSpeechPer"
android:title="在线朗读音色" android:title="在线朗读音色"
android:defaultValue="0"
android:entries="@array/tts_speech_per" android:entries="@array/tts_speech_per"
android:entryValues="@array/tts_speech_per_value" android:entryValues="@array/tts_speech_per_value"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />

Loading…
Cancel
Save