瀏覽代碼

语音功能优化

hurixing 10 月之前
父節點
當前提交
3c0bf2a411

+ 8 - 0
baselib/src/main/java/com/yingyangfly/baselib/bean/SpeechSynthesis.kt

@@ -0,0 +1,8 @@
+package com.yingyangfly.baselib.bean
+
+class SpeechSynthesis {
+
+    var sed: String = "5"
+    var voiceMsg: String = ""
+
+}

+ 5 - 1
baselib/src/main/java/com/yingyangfly/baselib/dialog/TaskFragment.kt

@@ -15,6 +15,7 @@ import com.bumptech.glide.Glide
 import com.gyf.immersionbar.BarHide
 import com.gyf.immersionbar.ktx.immersionBar
 import com.yingyangfly.baselib.R
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.ext.setOnSingleClickListener
 import com.yingyangfly.baselib.utils.LiveEventBusUtil
 import com.yingyangfly.baselib.utils.RxBusCodes
@@ -97,7 +98,10 @@ class TaskFragment : DialogFragment(), View.OnTouchListener {
      * 播放语音合成内容
      */
     private fun speak(taskDesn: String) {
-        LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, taskDesn)
+        val speechSynthesis = SpeechSynthesis().apply{
+            voiceMsg = taskDesn
+        }
+        LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, speechSynthesis)
     }
 
     @SuppressLint("ClickableViewAccessibility")

+ 1 - 1
config.gradle

@@ -13,7 +13,7 @@ ext {
             applicationId    : "com.yingyangfly",
             minSdkVersion    : 26,
             targetSdkVersion : 30,
-            versionCode      : 33,
+            versionCode      : 34,
             versionName      : "1.0.0",
     ]
     //androidx配置

+ 7 - 7
home/src/main/java/com/yingyangfly/home/activity/HomeActivity.kt

@@ -21,6 +21,7 @@ import com.yingyangfly.baselib.bean.HertzAudio
 import com.yingyangfly.baselib.bean.MessageBean
 import com.yingyangfly.baselib.bean.PurchaseConsultationEvent
 import com.yingyangfly.baselib.bean.Record
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.db.DepartmentBean
 import com.yingyangfly.baselib.db.VoicePlayerBean
 import com.yingyangfly.baselib.dialog.TipsDialog
@@ -37,7 +38,6 @@ import com.yingyangfly.baselib.mvvm.BaseMVVMActivity
 import com.yingyangfly.baselib.player.VoicePlayer
 import com.yingyangfly.baselib.router.RouterUrlCommon
 import com.yingyangfly.baselib.utils.*
-import com.yingyangfly.baselib.webview.utils.log
 import com.yingyangfly.home.adapter.ExclusiveGameAdapter
 import com.yingyangfly.home.adapter.GameAdapter
 import com.yingyangfly.home.adapter.HertzAudioAdapter
@@ -637,8 +637,8 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(), Vie
 
     private fun initLiveData() {
         //语音合成
-        LiveEventBusUtil.observer<String>(this, RxBusCodes.SPEECHSYNTHESIS) {
-            if (TextUtils.isEmpty(it).not()) {
+        LiveEventBusUtil.observer<SpeechSynthesis>(this, RxBusCodes.SPEECHSYNTHESIS) {
+            if (TextUtils.isEmpty(it.voiceMsg).not()) {
                 speak(it)
             }
         }
@@ -688,9 +688,9 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(), Vie
     /**
      * 语音合成
      */
-    private fun speak(desn: String) {
+    private fun speak(desn: SpeechSynthesis) {
         if (voicePlayerDao != null) {
-            val voicePlayerBean = voicePlayerDao?.getVoicePlayerBean(desn)
+            val voicePlayerBean = voicePlayerDao?.getVoicePlayerBean(desn.voiceMsg)
             if (voicePlayerBean != null) {
                 if (voicePlayer != null) {
                     voicePlayer?.play(voicePlayerBean.url) {
@@ -708,13 +708,13 @@ class HomeActivity : BaseMVVMActivity<ActivityHomeBinding, HomeViewModel>(), Vie
     /**
      * 获取声音url
      */
-    private fun getVoiceUrl(taskDesn: String) {
+    private fun getVoiceUrl(taskDesn: SpeechSynthesis) {
         viewModel.getVoiceUrl(taskDesn, fail = {}, success = {
             if (TextUtils.isEmpty(it).not()) {
                 if (voicePlayerDao != null) {
                     val voicePlayerBean = VoicePlayerBean().apply {
                         url = it
-                        words = taskDesn
+                        words = taskDesn.voiceMsg
                     }
                     voicePlayerDao?.insert(voicePlayerBean)
                 }

+ 2 - 1
home/src/main/java/com/yingyangfly/home/activity/HomeViewModel.kt

@@ -2,6 +2,7 @@ package com.yingyangfly.home.activity
 
 import com.yingyangfly.baselib.bean.HertzAudio
 import com.yingyangfly.baselib.bean.Record
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.db.DepartmentBean
 import com.yingyangfly.baselib.mvvm.BaseViewModel
 import com.yingyangfly.home.entity.CountTrainBean
@@ -80,7 +81,7 @@ class HomeViewModel : BaseViewModel() {
      * 获取声音url
      */
     fun getVoiceUrl(
-        msg: String,
+        msg: SpeechSynthesis,
         fail: ((msg: String) -> Unit)? = null,
         success: ((success: String?) -> Unit)? = null
     ) = launchFlow(false) {

+ 7 - 6
home/src/main/java/com/yingyangfly/home/evaluation/EvaluationActivity.kt

@@ -13,6 +13,7 @@ import com.tencent.imsdk.v2.V2TIMManager
 import com.yingyang.home.R
 import com.yingyang.home.databinding.ActivityEvaluationBinding
 import com.yingyangfly.baselib.bean.Evaluation
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.db.VoicePlayerBean
 import com.yingyangfly.baselib.ext.getEndAnimation
@@ -92,8 +93,8 @@ class EvaluationActivity : BaseMVVMActivity<ActivityEvaluationBinding, Evaluatio
     override fun initData() {
         if (!myBoolean) {
             //语音合成
-            LiveEventBusUtil.observer<String>(this, RxBusCodes.SPEECHSYNTHESIS) {
-                if (TextUtils.isEmpty(it).not()) {
+            LiveEventBusUtil.observer<SpeechSynthesis>(this, RxBusCodes.SPEECHSYNTHESIS) {
+                if (TextUtils.isEmpty(it.voiceMsg).not()) {
                     speak(it)
                 }
             }
@@ -154,9 +155,9 @@ class EvaluationActivity : BaseMVVMActivity<ActivityEvaluationBinding, Evaluatio
     /**
      * 语音合成
      */
-    private fun speak(desn: String) {
+    private fun speak(desn: SpeechSynthesis) {
         if (voicePlayerDao != null) {
-            val voicePlayerBean = voicePlayerDao?.getVoicePlayerBean(desn)
+            val voicePlayerBean = voicePlayerDao?.getVoicePlayerBean(desn.voiceMsg)
             if (voicePlayerBean != null) {
                 if (voicePlayer != null) {
                     voicePlayer?.play(voicePlayerBean.url) {
@@ -174,13 +175,13 @@ class EvaluationActivity : BaseMVVMActivity<ActivityEvaluationBinding, Evaluatio
     /**
      * 获取声音url
      */
-    private fun getVoiceUrl(taskDesn: String) {
+    private fun getVoiceUrl(taskDesn: SpeechSynthesis) {
         viewModel.getVoiceUrl(taskDesn, fail = {}, success = {
             if (TextUtils.isEmpty(it).not()) {
                 if (voicePlayerDao != null) {
                     val voicePlayerBean = VoicePlayerBean().apply {
                         url = it
-                        words = taskDesn
+                        words = taskDesn.voiceMsg
                     }
                     voicePlayerDao?.insert(voicePlayerBean)
                 }

+ 5 - 4
home/src/main/java/com/yingyangfly/home/evaluation/EvaluationViewModel.kt

@@ -1,5 +1,6 @@
 package com.yingyangfly.home.evaluation
 
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.mvvm.BaseViewModel
 import com.yingyangfly.baselib.net.XUtils
@@ -21,7 +22,7 @@ class EvaluationViewModel : BaseViewModel() {
     fun getQuestions(
         method: String,
         fail: ((msg: String) -> Unit)? = null,
-        success: ((success: List<QuestionsBean>?) -> Unit)? = null,
+        success: ((success: List<QuestionsBean>?) -> Unit)? = null
     ) = launchFlow(true) {
         val requestBean = QuestionsTypeBean().apply {
             type = method
@@ -40,7 +41,7 @@ class EvaluationViewModel : BaseViewModel() {
         method: String,
         stast: String,
         fail: ((msg: String) -> Unit)? = null,
-        success: ((success: ReviewTaskListBean?) -> Unit)? = null,
+        success: ((success: ReviewTaskListBean?) -> Unit)? = null
     ) = launchFlow(true) {
         val requestBean = ReviewTask().apply {
             type = method
@@ -55,7 +56,7 @@ class EvaluationViewModel : BaseViewModel() {
 
     fun logout(
         fail: ((msg: String) -> Unit)? = null,
-        success: ((success: String?) -> Unit)? = null,
+        success: ((success: String?) -> Unit)? = null
     ) = launchFlow(true) {
         HOME_API.logout()
     }.runUI(
@@ -67,7 +68,7 @@ class EvaluationViewModel : BaseViewModel() {
      * 获取声音url
      */
     fun getVoiceUrl(
-        msg: String,
+        msg: SpeechSynthesis,
         fail: ((msg: String) -> Unit)? = null,
         success: ((success: String?) -> Unit)? = null
     ) = launchFlow(false) {

+ 2 - 1
home/src/main/java/com/yingyangfly/home/net/HomeApiService.kt

@@ -2,6 +2,7 @@ package com.yingyangfly.home.net
 
 import com.yingyangfly.baselib.bean.HertzAudio
 import com.yingyangfly.baselib.bean.Record
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.db.DepartmentBean
 import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.net.BaseResp
@@ -54,7 +55,7 @@ interface HomeApiService {
      */
     @POST("app/video/getVoiceUrl")
     suspend fun getVoiceUrl(
-        @Query("voiceMsg") voiceMsg: String
+        @Body speechSynthesis: SpeechSynthesis
     ): BaseResp<String>
 
 

+ 5 - 1
mmse/src/main/java/com/yingyangfly/mmse/fragment/JudgmentRecordFragment.kt

@@ -10,6 +10,7 @@ import androidx.navigation.Navigation
 import com.yingyang.mmse.R
 import com.yingyang.mmse.databinding.FragmentJudgmentRecordBinding
 import com.yingyangfly.baselib.base.BaseFragment
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.ext.getEndAnimation
 import com.yingyangfly.baselib.ext.getScaleAnimation
@@ -104,9 +105,12 @@ class JudgmentRecordFragment : BaseFragment<FragmentJudgmentRecordBinding>(), Vi
                     }
                     R.id.soundImage -> {
                         if (question != null) {
+                            val speechSynthesis = SpeechSynthesis().apply{
+                                voiceMsg = question?.reviewItem!!
+                            }
                             LiveEventBusUtil.send(
                                 RxBusCodes.SPEECHSYNTHESIS,
-                                question?.reviewItem!!
+                                speechSynthesis
                             )
                         }
                     }

+ 5 - 1
mmse/src/main/java/com/yingyangfly/mmse/fragment/RecordActionFragment.kt

@@ -9,6 +9,7 @@ import androidx.navigation.Navigation
 import com.yingyang.mmse.R
 import com.yingyang.mmse.databinding.FragmentRecordActionBinding
 import com.yingyangfly.baselib.base.BaseFragment
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.ext.getEndAnimation
 import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.utils.LiveEventBusUtil
@@ -99,7 +100,10 @@ class RecordActionFragment : BaseFragment<FragmentRecordActionBinding>(), View.O
                         val stringBuffer = StringBuffer()
                         stringBuffer.append(firstWord).append(",").append(secondWord).append(",")
                             .append(thirdWord)
-                        LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, stringBuffer.toString())
+                        val speechSynthesis = SpeechSynthesis().apply{
+                            voiceMsg = stringBuffer.toString()
+                        }
+                        LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, speechSynthesis)
                     }
                 }
             }

+ 6 - 1
mmse/src/main/java/com/yingyangfly/mmse/fragment/SoundRecordFragment.kt

@@ -9,6 +9,7 @@ import androidx.navigation.Navigation
 import com.yingyang.mmse.R
 import com.yingyang.mmse.databinding.FragmentSoundRecordBinding
 import com.yingyangfly.baselib.base.BaseFragment
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.ext.getEndAnimation
 import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.utils.LiveEventBusUtil
@@ -102,7 +103,11 @@ class SoundRecordFragment : BaseFragment<FragmentSoundRecordBinding>(), View.OnT
                         val stringBuffer = StringBuffer()
                         stringBuffer.append(firstWord).append(",").append(secondWord).append(",")
                             .append(thirdWord)
-                        LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, stringBuffer.toString())
+
+                        val speechSynthesis = SpeechSynthesis().apply{
+                            voiceMsg = stringBuffer.toString()
+                        }
+                        LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, speechSynthesis)
                     }
                 }
             }

+ 6 - 1
moca/src/main/java/com/yingyangfly/moca/listenspeak/ListenSpeakFragment.kt

@@ -9,6 +9,7 @@ import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentListenSpeakBinding
 import com.yingyangfly.baselib.base.BaseFragment
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.ext.getEndAnimation
 import com.yingyangfly.baselib.ext.getScaleAnimation
@@ -88,7 +89,11 @@ class ListenSpeakFragment : BaseFragment<FragmentListenSpeakBinding>(),
                     }
                     R.id.imagePlay -> {
                         if (questionsBean != null) {
-                            LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, questionsBean?.reviewDesc!!)
+                            val speechSynthesis = SpeechSynthesis().apply{
+                                voiceMsg = questionsBean?.reviewDesc!!
+                            }
+
+                            LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, speechSynthesis)
                         }
                     }
                 }

+ 5 - 1
moca/src/main/java/com/yingyangfly/moca/listenspeak/MiniCogInitializeFragment.kt

@@ -9,6 +9,7 @@ import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentMiniCogInitializeBinding
 import com.yingyangfly.baselib.base.BaseFragment
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.ext.getEndAnimation
 import com.yingyangfly.baselib.ext.getScaleAnimation
@@ -79,7 +80,10 @@ class MiniCogInitializeFragment : BaseFragment<FragmentMiniCogInitializeBinding>
                     }
                     R.id.imagePlay -> {
                         if (questionsBean != null) {
-                            LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, questionsBean?.reviewDesc!!)
+                            val speechSynthesis = SpeechSynthesis().apply{
+                                voiceMsg = questionsBean?.reviewDesc!!
+                            }
+                            LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, speechSynthesis)
                         }
                     }
                 }

+ 6 - 1
moca/src/main/java/com/yingyangfly/moca/memorizenumbers/MemorizeNumbersFragment.kt

@@ -9,6 +9,7 @@ import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentMemorizeNumbersBinding
 import com.yingyangfly.baselib.base.BaseFragment
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.db.QuestionsBean
 import com.yingyangfly.baselib.ext.getEndAnimation
 import com.yingyangfly.baselib.ext.getScaleAnimation
@@ -98,7 +99,11 @@ class MemorizeNumbersFragment : BaseFragment<FragmentMemorizeNumbersBinding>(),
                     }
                     R.id.imagePlay -> {
                         if (question != null) {
-                            LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, question?.reviewDesc!!)
+                            val speechSynthesis = SpeechSynthesis().apply{
+                                voiceMsg = question?.reviewDesc!!
+                                sed = "1"
+                            }
+                            LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, speechSynthesis)
                         }
                     }
                 }

+ 6 - 1
moca/src/main/java/com/yingyangfly/moca/record/ListenRecordFragment.kt

@@ -9,6 +9,7 @@ import androidx.navigation.Navigation
 import com.yingyang.moca.R
 import com.yingyang.moca.databinding.FragmentListenRecordBinding
 import com.yingyangfly.baselib.base.BaseFragment
+import com.yingyangfly.baselib.bean.SpeechSynthesis
 import com.yingyangfly.baselib.ext.getEndAnimation
 import com.yingyangfly.baselib.ext.getScaleAnimation
 import com.yingyangfly.baselib.utils.LiveEventBusUtil
@@ -120,7 +121,11 @@ class ListenRecordFragment : BaseFragment<FragmentListenRecordBinding>(),
                                 stringBuffer.append("、"+it)
                             }
                         }
-                        LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, stringBuffer.toString())
+
+                        val speechSynthesis = SpeechSynthesis().apply{
+                            voiceMsg = stringBuffer.toString()
+                        }
+                        LiveEventBusUtil.send(RxBusCodes.SPEECHSYNTHESIS, speechSynthesis)
                     }
                 }
             }