将车聊聊工程代码加入到项目中,保证能跑起来了,后续做架构升级
Signed-off-by: 董宏宇 <martindhy@gmail.com>
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package com.mogo.chat.voice
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter
|
||||
import com.mogo.chat.constant.TAG
|
||||
import com.mogo.chat.util.log
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.voice.AIAssist
|
||||
import com.mogo.commons.voice.IMogoVoiceCmdCallBack
|
||||
import com.mogo.eagle.core.data.constants.MogoServicePaths
|
||||
import com.mogo.service.IMogoServiceApis
|
||||
import com.mogo.service.intent.IMogoIntentManager
|
||||
|
||||
|
||||
object IMVoiceClient {
|
||||
|
||||
private var intentRegister: IMogoIntentManager? = null
|
||||
|
||||
private const val REQUEST_VOICE_CALL = "主人,有新的小伙伴找你聊天啦,你要接听吗?你可以说“接听”开启通话。或者说“挂断”结束通话"
|
||||
private const val REQUEST_CLOUD_VOICE_CALL = "您有来自管理平台的语音电话,请接听!"
|
||||
private val requestCallYArray: Array<String> = arrayOf("接听")
|
||||
private val requestCallNArray: Array<String> = arrayOf("挂断")
|
||||
|
||||
const val VOICE_INTENT_ANSWER_CALL = "com.ileja.phone.incoming.accept" //接听
|
||||
const val VOICE_INTENT_REFUSE_CALL = "com.ileja.phone.incoming.reject" //挂断(包括拨出时挂断和来电挂断)
|
||||
|
||||
init {
|
||||
log(TAG, "init")
|
||||
val register =
|
||||
ARouter.getInstance().build(MogoServicePaths.PATH_SERVICE_APIS).navigation()
|
||||
if (register is IMogoServiceApis) {
|
||||
intentRegister = register.intentManagerApi
|
||||
}
|
||||
}
|
||||
|
||||
private var onCmdAgree: ((Boolean) -> Unit)? = null
|
||||
|
||||
private var onSpeedFinish: (() -> Unit)? = null
|
||||
|
||||
fun registerIntentInComingCall(listener: IVoiceIntentListener) {
|
||||
intentRegister?.registerIntentListener(VOICE_INTENT_ANSWER_CALL, listener)
|
||||
intentRegister?.registerIntentListener(VOICE_INTENT_REFUSE_CALL, listener)
|
||||
}
|
||||
|
||||
fun unRegisterIntentInComingCall(listener: IVoiceIntentListener) {
|
||||
intentRegister?.unregisterIntentListener(VOICE_INTENT_ANSWER_CALL, listener)
|
||||
intentRegister?.unregisterIntentListener(VOICE_INTENT_REFUSE_CALL, listener)
|
||||
}
|
||||
|
||||
fun speakAndRegisterCall(onCmdAgree: ((Boolean) -> Unit), onSpeedFinish: (() -> Unit)) {
|
||||
IMVoiceClient.onCmdAgree = onCmdAgree
|
||||
IMVoiceClient.onSpeedFinish = onSpeedFinish
|
||||
AIAssist.getInstance(AbsMogoApplication.getApp().applicationContext).speakQAndACmd(REQUEST_CLOUD_VOICE_CALL,
|
||||
requestCallYArray, requestCallNArray, object : IMogoVoiceCmdCallBack {
|
||||
override fun onCmdAction(speakText: String?) {
|
||||
super.onCmdAction(speakText)
|
||||
log(TAG, "onCmdAction ---> ")
|
||||
IMVoiceClient.onCmdAgree?.invoke(true)
|
||||
}
|
||||
|
||||
override fun onCmdCancel(speakText: String?) {
|
||||
super.onCmdCancel(speakText)
|
||||
log(TAG, "onCmdCancel ---> ")
|
||||
IMVoiceClient.onCmdAgree?.invoke(false)
|
||||
}
|
||||
|
||||
override fun onSpeakEnd(speakText: String?) {
|
||||
super.onSpeakEnd(speakText)
|
||||
log(TAG, "onSpeakEnd ---> ")
|
||||
IMVoiceClient.onSpeedFinish?.invoke()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun releaseSpeakAndRegisterCallback() {
|
||||
onCmdAgree = null
|
||||
onSpeedFinish = null
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.mogo.chat.voice
|
||||
|
||||
import android.content.Intent
|
||||
import com.mogo.chat.constant.TAG
|
||||
import com.mogo.chat.util.log
|
||||
import com.mogo.chat.voice.IMVoiceClient.VOICE_INTENT_ANSWER_CALL
|
||||
import com.mogo.chat.voice.IMVoiceClient.VOICE_INTENT_REFUSE_CALL
|
||||
import com.mogo.service.intent.IMogoIntentListener
|
||||
|
||||
|
||||
interface IVoiceIntentListener :IMogoIntentListener{
|
||||
|
||||
override fun onIntentReceived(intentStr: String?, intent: Intent?) {
|
||||
log(TAG, "onIntentCommand intentStr:$intentStr")
|
||||
when (intentStr) {
|
||||
VOICE_INTENT_ANSWER_CALL -> {
|
||||
onVoiceAnswerCall()
|
||||
}
|
||||
VOICE_INTENT_REFUSE_CALL -> {
|
||||
onVoiceRefuseCall()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun onVoiceAnswerCall()
|
||||
|
||||
fun onVoiceRefuseCall()
|
||||
}
|
||||
Reference in New Issue
Block a user