pull/32/head
kunfei 5 years ago
parent d7b85b6636
commit a1348e7976
  1. 16
      app/src/main/java/io/legado/app/service/ReadAloudService.kt
  2. 26
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt
  3. 2
      app/src/main/res/layout/dialog_read_aloud.xml

@ -19,6 +19,7 @@ import io.legado.app.help.MediaHelp
import io.legado.app.receiver.MediaButtonReceiver import io.legado.app.receiver.MediaButtonReceiver
import io.legado.app.service.notification.ReadAloudNotification import io.legado.app.service.notification.ReadAloudNotification
import io.legado.app.ui.widget.page.TextChapter import io.legado.app.ui.widget.page.TextChapter
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.postEvent import io.legado.app.utils.postEvent
import io.legado.app.utils.toast import io.legado.app.utils.toast
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -73,6 +74,14 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
} }
} }
fun upTtsSpeechRate(context: Context) {
if (isRun) {
val intent = Intent(context, ReadAloudService::class.java)
intent.action = "upTtsSpeechRate"
context.startService(intent)
}
}
fun clearTTS() { fun clearTTS() {
textToSpeech?.stop() textToSpeech?.stop()
textToSpeech?.shutdown() textToSpeech?.shutdown()
@ -107,6 +116,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
initMediaSession() initMediaSession()
initBroadcastReceiver() initBroadcastReceiver()
upMediaSessionPlaybackState() upMediaSessionPlaybackState()
upSpeechRate()
ReadAloudNotification.upNotification(this) ReadAloudNotification.upNotification(this)
} }
@ -132,7 +142,7 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
} }
"pause" -> pauseReadAloud(true) "pause" -> pauseReadAloud(true)
"resume" -> resumeReadAloud() "resume" -> resumeReadAloud()
"stop" -> stopSelf() "upTtsSpeechRate" -> upSpeechRate()
else -> stopSelf() else -> stopSelf()
} }
} }
@ -189,6 +199,10 @@ class ReadAloudService : BaseService(), TextToSpeech.OnInitListener, AudioManage
} }
} }
private fun upSpeechRate() {
textToSpeech?.setSpeechRate((this.getPrefInt("ttsSpeechRate", 5) + 5) / 10f)
}
/** /**
* 初始化MediaSession * 初始化MediaSession
*/ */

@ -6,6 +6,7 @@ import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.SeekBar
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
@ -60,7 +61,7 @@ class ReadAloudDialog : DialogFragment() {
cb_by_page.isChecked = requireContext().getPrefBoolean("readAloudByPage") cb_by_page.isChecked = requireContext().getPrefBoolean("readAloudByPage")
cb_tts_follow_sys.isChecked = requireContext().getPrefBoolean("ttsFollowSys", true) cb_tts_follow_sys.isChecked = requireContext().getPrefBoolean("ttsFollowSys", true)
seek_tts_SpeechRate.isEnabled = !cb_tts_follow_sys.isChecked seek_tts_SpeechRate.isEnabled = !cb_tts_follow_sys.isChecked
seek_tts_SpeechRate.progress = requireContext().getPrefInt("ttsSpeechRate", 10) seek_tts_SpeechRate.progress = requireContext().getPrefInt("ttsSpeechRate", 5)
} }
private fun initOnChange() { private fun initOnChange() {
@ -73,8 +74,22 @@ class ReadAloudDialog : DialogFragment() {
if (buttonView.isPressed) { if (buttonView.isPressed) {
requireContext().putPrefBoolean("ttsFollowSys", isChecked) requireContext().putPrefBoolean("ttsFollowSys", isChecked)
seek_tts_SpeechRate.isEnabled = !isChecked seek_tts_SpeechRate.isEnabled = !isChecked
upTtsSpeechRate()
} }
} }
seek_tts_SpeechRate.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
}
override fun onStartTrackingTouch(seekBar: SeekBar?) {
}
override fun onStopTrackingTouch(seekBar: SeekBar?) {
requireContext().putPrefInt("ttsSpeechRate", seek_tts_SpeechRate.progress)
upTtsSpeechRate()
}
})
} }
private fun initOnClick() { private fun initOnClick() {
@ -97,4 +112,13 @@ class ReadAloudDialog : DialogFragment() {
} }
} }
private fun upTtsSpeechRate() {
val activity = activity
if (activity is ReadBookActivity) {
if (activity.readAloudStatus == Status.PLAY) {
ReadAloudService.pause(requireContext())
ReadAloudService.resume(requireContext())
}
}
}
} }

@ -161,7 +161,7 @@
android:layout_height="30dp" android:layout_height="30dp"
android:layout_marginStart="15dp" android:layout_marginStart="15dp"
android:layout_marginEnd="15dp" android:layout_marginEnd="15dp"
android:max="50" /> android:max="45" />
</LinearLayout> </LinearLayout>

Loading…
Cancel
Save