|
|
@@ -8,6 +8,7 @@ import android.view.View
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route
|
|
|
import com.yingyangfly.baselib.bean.def.PermissionList
|
|
|
import com.yingyangfly.baselib.db.QuestionsBean
|
|
|
+import com.yingyangfly.baselib.db.VoicePlayerBean
|
|
|
import com.yingyangfly.baselib.dialog.BindingPhoneDialog
|
|
|
import com.yingyangfly.baselib.ext.check
|
|
|
import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
@@ -15,8 +16,11 @@ import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
import com.yingyangfly.baselib.ext.show
|
|
|
import com.yingyangfly.baselib.ext.toast
|
|
|
import com.yingyangfly.baselib.mvvm.BaseTvMVVMActivity
|
|
|
+import com.yingyangfly.baselib.player.VoicePlayer
|
|
|
import com.yingyangfly.baselib.router.RouterUrlCommon
|
|
|
import com.yingyangfly.baselib.utils.JumpUtil
|
|
|
+import com.yingyangfly.baselib.utils.LiveEventBusUtil
|
|
|
+import com.yingyangfly.baselib.utils.RxBusCodes
|
|
|
import com.yingyangfly.baselib.utils.User
|
|
|
import com.yingyangfly.evaluation.R
|
|
|
import com.yingyangfly.evaluation.databinding.ActivityHospitalBinding
|
|
|
@@ -36,8 +40,14 @@ class HospitalActivity : BaseTvMVVMActivity<ActivityHospitalBinding, HospitalVie
|
|
|
private var reviewTaskId = ""
|
|
|
private var taskId = ""
|
|
|
|
|
|
+ /**
|
|
|
+ * 语音合成
|
|
|
+ */
|
|
|
+ private var voicePlayer: VoicePlayer? = null
|
|
|
+
|
|
|
@SuppressLint("SetTextI18n")
|
|
|
override fun initViews() {
|
|
|
+ voicePlayer = VoicePlayer.getInstance(mContext)
|
|
|
initPermission()
|
|
|
adapterGuide = GuidePageAdapter(imageList, mContext)
|
|
|
binding.guide.addBannerLifecycleObserver(this)?.setAdapter(adapterGuide)?.indicator =
|
|
|
@@ -70,7 +80,71 @@ class HospitalActivity : BaseTvMVVMActivity<ActivityHospitalBinding, HospitalVie
|
|
|
}
|
|
|
|
|
|
override fun initData() {
|
|
|
+ initLiveData()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun initLiveData() {
|
|
|
+ //语音合成
|
|
|
+ LiveEventBusUtil.observer<String>(this, RxBusCodes.SPEECHSYNTHESIS) {
|
|
|
+ if (TextUtils.isEmpty(it).not()) {
|
|
|
+ speak(it)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //结束语音播放
|
|
|
+ LiveEventBusUtil.observer<String>(this, RxBusCodes.STOPVOICE) {
|
|
|
+ if (voicePlayer != null) {
|
|
|
+ if (voicePlayer!!.isPlaying) {
|
|
|
+ voicePlayer?.stop()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 语音合成
|
|
|
+ */
|
|
|
+ private fun speak(desn: String) {
|
|
|
+ if (db != null) {
|
|
|
+ val voicePlayerDao = db?.getVoicePlayerDao()
|
|
|
+ if (voicePlayerDao != null) {
|
|
|
+ val voicePlayerBean = voicePlayerDao.getVoicePlayerBean(desn)
|
|
|
+ if (voicePlayerBean != null) {
|
|
|
+ if (voicePlayer != null) {
|
|
|
+ voicePlayer?.play(voicePlayerBean.url) {}
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ getVoiceUrl(desn)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ getVoiceUrl(desn)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ getVoiceUrl(desn)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取声音url
|
|
|
+ */
|
|
|
+ private fun getVoiceUrl(taskDesn: String) {
|
|
|
+ viewModel.getVoiceUrl(taskDesn, fail = {}, success = {
|
|
|
+ if (TextUtils.isEmpty(it).not()) {
|
|
|
+ if (db != null) {
|
|
|
+ val voicePlayerDao = db?.getVoicePlayerDao()
|
|
|
+ if (voicePlayerDao != null) {
|
|
|
+ val voicePlayerBean = VoicePlayerBean().apply {
|
|
|
+ url = it
|
|
|
+ words = taskDesn
|
|
|
+ }
|
|
|
+ voicePlayerDao.insert(voicePlayerBean)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (voicePlayer != null) {
|
|
|
+ voicePlayer?.play(it) {}
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
@SuppressLint("ClickableViewAccessibility")
|