|
|
@@ -1,10 +1,15 @@
|
|
|
package com.nova.brain.glass.helper
|
|
|
|
|
|
+import android.R.attr.action
|
|
|
import android.app.AlertDialog
|
|
|
+import android.graphics.Color
|
|
|
+import android.graphics.drawable.GradientDrawable
|
|
|
import android.os.Handler
|
|
|
import android.os.Looper
|
|
|
import android.util.Log
|
|
|
+import android.view.LayoutInflater
|
|
|
import com.nova.brain.glass.BuildConfig
|
|
|
+import com.nova.brain.glass.R
|
|
|
import com.nova.brain.glass.model.RecognizeAction
|
|
|
import com.rokid.online.speech.AsrClient
|
|
|
import com.rokid.online.speech.OnlineSpeechSdk
|
|
|
@@ -57,6 +62,9 @@ object AsrHelper : OfflineCmdListener {
|
|
|
/** goToDecisionCenter 命中时的回调,由各 Activity 在 onResume/onPause 中注册/清空 */
|
|
|
var onGoToDecisionCenter: ((action: RecognizeAction) -> Unit)? = null
|
|
|
|
|
|
+ /** scene == "decision" 时直接用 ASR 文本发起对话,由 ChatActivity 注册 */
|
|
|
+ var onDirectChat: ((text: String) -> Unit)? = null
|
|
|
+
|
|
|
fun init() {
|
|
|
val cfg = OnlineSpeechSdkConfig(
|
|
|
domain = DOMAIN,
|
|
|
@@ -121,11 +129,28 @@ object AsrHelper : OfflineCmdListener {
|
|
|
val activity = runCatching { AppManager.getInstance().getActivity() }.getOrNull()
|
|
|
?: return@post
|
|
|
if (activity.isFinishing || activity.isDestroyed) return@post
|
|
|
+
|
|
|
+ val contentView = LayoutInflater.from(activity)
|
|
|
+ .inflate(R.layout.dialog_listening, null)
|
|
|
+
|
|
|
+ // 黑底 + 绿色圆角线框
|
|
|
+ val density = activity.resources.displayMetrics.density
|
|
|
+ contentView.background = GradientDrawable().apply {
|
|
|
+ shape = GradientDrawable.RECTANGLE
|
|
|
+ cornerRadius = 12f * density
|
|
|
+ setColor(Color.BLACK)
|
|
|
+ setStroke((2f * density).toInt(), Color.parseColor("#FF40FF5E"))
|
|
|
+ }
|
|
|
+
|
|
|
listeningDialog = AlertDialog.Builder(activity)
|
|
|
- .setMessage("飞宝在呢,您请说")
|
|
|
+ .setView(contentView)
|
|
|
.setCancelable(false)
|
|
|
.create()
|
|
|
- .also { it.show() }
|
|
|
+ .also { dialog ->
|
|
|
+ dialog.show()
|
|
|
+ // 让 Dialog 窗口本身透明,只显示自定义 view 的背景
|
|
|
+ dialog.window?.setBackgroundDrawableResource(android.R.color.transparent)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -162,17 +187,21 @@ object AsrHelper : OfflineCmdListener {
|
|
|
asr?.stopAsrWithMic()
|
|
|
Log.d(TAG, "ASR final result: $text")
|
|
|
dismissListeningDialog()
|
|
|
- IntentRecognizeHelper.recognize(
|
|
|
- text = text,
|
|
|
- scence = scene,
|
|
|
- onSuccess = { action ->
|
|
|
- if (action.name == "goToDecisionCenter") {
|
|
|
- onGoToDecisionCenter?.invoke(action)
|
|
|
- } else {
|
|
|
- "需要跳转任务列表".showMessage()
|
|
|
+ if (scene == "decision") {
|
|
|
+ onDirectChat?.invoke(text)
|
|
|
+ } else {
|
|
|
+ IntentRecognizeHelper.recognize(
|
|
|
+ text = text,
|
|
|
+ scence = scene,
|
|
|
+ onSuccess = { action ->
|
|
|
+ if (action.name == "goToDecisionCenter") {
|
|
|
+ onGoToDecisionCenter?.invoke(action)
|
|
|
+ } else {
|
|
|
+ "需要跳转任务列表".showMessage()
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- )
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onFinished(taskId: String) {
|