[6.2.0][V2X] 简化V2X事件语音播报逻辑
This commit is contained in:
@@ -2,13 +2,11 @@ package com.mogo.eagle.core.function.hmi.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import android.util.*
|
||||
import android.view.*
|
||||
import androidx.lifecycle.ProcessLifecycleOwner
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.commons.voice.AIAssist
|
||||
import com.mogo.commons.voice.IMogoVoiceCmdCallBack
|
||||
import com.mogo.eagle.core.data.deva.bindingcar.IPCUpgradeStateInfo
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
||||
import com.mogo.eagle.core.data.constants.MogoServicePaths.PATH_FRAGMENT_HMI
|
||||
@@ -39,7 +37,6 @@ import com.mogo.eagle.core.function.hmi.ui.tools.ModifyBindingCarDialog
|
||||
import com.mogo.eagle.core.function.hmi.ui.tools.ToBindingCarDialog
|
||||
import com.mogo.eagle.core.function.hmi.ui.tools.UpgradeAppDialog
|
||||
import com.mogo.eagle.core.function.hmi.ui.utils.HmiActionLog
|
||||
import com.mogo.eagle.core.function.hmi.ui.vehicle.TurnLightViewStatus
|
||||
import com.mogo.eagle.core.function.hmi.ui.widget.StatusBarView
|
||||
import com.mogo.eagle.core.utilcode.floating.*
|
||||
import com.mogo.eagle.core.utilcode.kotlin.safeCancel
|
||||
@@ -47,9 +44,10 @@ import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_HMI
|
||||
import com.mogo.eagle.core.utilcode.util.*
|
||||
import com.mogo.tts.base.IMogoTTSCallback
|
||||
import com.zhjt.service_biz.BizConfig
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.selects.*
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
/**
|
||||
@@ -64,7 +62,6 @@ class MoGoHmiProvider : IMoGoHmiProvider {
|
||||
private const val TAG = "MoGoHmiProvider"
|
||||
}
|
||||
|
||||
private val lastSpeakJob by lazy { AtomicReference<Job>() }
|
||||
private var lastShowV2XJob: Job? = null
|
||||
private var context: Context? = null
|
||||
|
||||
@@ -73,7 +70,8 @@ class MoGoHmiProvider : IMoGoHmiProvider {
|
||||
*/
|
||||
private val lookAround by lazy { AtomicReference<MoGoPopWindow>() }
|
||||
|
||||
private val scope by lazy { CoroutineScope(Dispatchers.Default + SupervisorJob()) }
|
||||
private val isPlayingTts by lazy { AtomicBoolean(false) }
|
||||
|
||||
|
||||
override fun init(context: Context?) {
|
||||
this.context = context
|
||||
@@ -145,66 +143,27 @@ class MoGoHmiProvider : IMoGoHmiProvider {
|
||||
}.invokeOnCompletion {
|
||||
listener?.onDismiss()
|
||||
}
|
||||
Log.d("CODE", "---- 00 ------ tts_content: $ttsContent")
|
||||
if (ttsContent != null && !TextUtils.isEmpty(ttsContent) && playTTS) {
|
||||
val last = lastSpeakJob.get()
|
||||
Log.d("CODE", "---- 0 ------: last: $last")
|
||||
if (last != null && !last.isCompleted) {
|
||||
Log.d("CODE", "---- 1 ------")
|
||||
return
|
||||
}
|
||||
scope.launch {
|
||||
Log.d("CODE", "---- 2 ------")
|
||||
val d1 = async {
|
||||
Log.d("CODE", "---- 2_1 start ------")
|
||||
speak(it, ttsContent)
|
||||
Log.d("CODE", "---- 2_1 end ------")
|
||||
}
|
||||
val d2 = async {
|
||||
Log.d("CODE", "---- 2_2 start ------")
|
||||
delay((305.75 * ttsContent.length).toLong())
|
||||
Log.d("CODE", "---- 2_2 end ------")
|
||||
}
|
||||
val ret = select<Int> {
|
||||
d1.onAwait { 1 }
|
||||
d2.onAwait { 2 }
|
||||
}
|
||||
if (ret == 1) {
|
||||
d2.cancel()
|
||||
Log.d("CODE", "---- 3 ------")
|
||||
} else {
|
||||
d1.cancel()
|
||||
Log.d("CODE", "---- 4 ------")
|
||||
}
|
||||
}.also { itx ->
|
||||
lastSpeakJob.set(itx)
|
||||
if (!isPlayingTts.get() && ttsContent != null && !TextUtils.isEmpty(ttsContent) && playTTS) {
|
||||
context?.also {
|
||||
AIAssist.getInstance(it).speakTTSVoiceWithLevel(ttsContent, AIAssist.LEVEL2, object : IMogoTTSCallback {
|
||||
|
||||
override fun onSpeakEnd(speakText: String?) {
|
||||
super.onSpeakEnd(speakText)
|
||||
isPlayingTts.set(false)
|
||||
}
|
||||
|
||||
override fun onSpeakError(speakText: String?, errorMsg: String?) {
|
||||
super.onSpeakError(speakText, errorMsg)
|
||||
isPlayingTts.set(false)
|
||||
}
|
||||
})
|
||||
isPlayingTts.set(true)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun speak(ctx: Context, text: String) = suspendCancellableCoroutine<Unit> {
|
||||
try {
|
||||
val voiceCallback = object : IMogoVoiceCmdCallBack {
|
||||
override fun onSpeakEnd(speakText: String?) {
|
||||
super.onSpeakEnd(speakText)
|
||||
it.resumeWith(Result.success(Unit))
|
||||
}
|
||||
|
||||
override fun onSpeakError(speakText: String?, errorMsg: String?) {
|
||||
super.onSpeakError(speakText, errorMsg)
|
||||
it.resumeWith(Result.success(Unit))
|
||||
}
|
||||
}
|
||||
it.invokeOnCancellation {
|
||||
AIAssist.getInstance(ctx).stopSpeakTts(text)
|
||||
}
|
||||
AIAssist.getInstance(ctx).speakTTSVoiceWithLevel(text, AIAssist.LEVEL2, voiceCallback)
|
||||
} catch (t: Throwable) {
|
||||
it.resumeWith(Result.success(Unit))
|
||||
CallerLogger.w("$M_HMI$TAG", t.message)
|
||||
}
|
||||
}
|
||||
|
||||
override fun showWarning(v2xType: String, direction: WarningDirectionEnum, expireTime: Long) {
|
||||
//CallerV2XWarningListenerManager.show(v2xType, direction, expireTime)
|
||||
|
||||
Reference in New Issue
Block a user