fix(voice): 更新唤醒词并优化AI异常处理

- 将唤醒词从"我的任务"更改为"飞宝飞宝"
- 添加JSONObject和HttpException导入
- 实现HttpException响应体解析获取详细错误信息
- 当AI返回异常时更新最后一条聊天内容显示具体错误
- 优化错误消息显示逻辑确保用户体验
这个提交包含在:
徐勤民 2026-04-16 23:25:32 +08:00
父节点 cfb2e6cad9
当前提交 7d47f557b1
共有 3 个文件被更改,包括 18 次插入3 次删除

查看文件

@ -26,7 +26,7 @@ object AsrHelper : OfflineCmdListener {
// 唤醒词Nova Nova
private const val WAKE_WORD = "Nova Nova"
private const val WAKE_WORD1 = "我的任务"
private const val WAKE_WORD1 = "飞宝飞宝"
private const val WAKE_WORD_PINYIN = "nou wa nou wa"
private var sdk: OnlineSpeechSdk? = null

查看文件

@ -129,7 +129,7 @@ object OfflineCmdServiceHelper {
OfflineCmdBean("Nova Nova", "nao wa nao wa"),
OfflineCmdBean("C大脑", "c da nao"),
OfflineCmdBean("C大脑", "sei da nao"),
OfflineCmdBean("我的任务", "wo de ren wu")
OfflineCmdBean("飞宝飞宝", "fei bao fei bao"),
)
)
}

查看文件

@ -16,6 +16,8 @@ import com.xuqm.base.viewmodel.BaseListViewModel
import com.xuqm.base.viewmodel.callback.Response
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import org.json.JSONObject
import retrofit2.HttpException
import java.util.UUID
class ChatVM : BaseListViewModel<ChatItem>() {
@ -124,7 +126,20 @@ class ChatVM : BaseListViewModel<ChatItem>() {
}, { e ->
LogHelper.e(">>>>22", e)
loading.postValue(false)
result.postValue("AI反馈异常: ${e.message}")
val errMsg = if (e is HttpException) {
runCatching {
val body = e.response()?.errorBody()?.string() ?: ""
JSONObject(body).optString("msg", e.message())
}.getOrDefault(e.message())
} else {
"AI反馈异常: ${e.message}"
}
val lastIndex = chatItems.size - 1
if (lastIndex >= 0) {
chatItems[lastIndex].content = errMsg
notifyItem(lastIndex)
}
result.postValue(errMsg)
})
currentTask?.also { add(it) }
}