diff --git a/.env.development b/.env.development
index 42373a3c..4339c237 100644
--- a/.env.development
+++ b/.env.development
@@ -7,7 +7,7 @@ ENV = 'development'
#VITE_APP_BASE_API_Url = 'https://aits.jlbank.com.cn:7002'
-VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7001'
+#VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7002'
# VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7002'
# VITE_APP_BASE_API_Url = 'http://192.168.247.200'
@@ -15,19 +15,14 @@ VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7001'
# VITE_APP_BASE_API_Url = 'http://192.168.108.129'
# dev
-
-#VITE_APP_BASE_API_Url = 'http://25.18.122.65:7001'
-
-
+# DEV
+VITE_APP_BASE_API_Url = 'http://25.18.122.65:7001'
# sit
-
#VITE_APP_BASE_API_Url = 'http://25.18.122.91:9786'
-
# UAT
# VITE_APP_BASE_API_Url = 'http://25.18.122.78:9786'
-# DEV
# app入口
@@ -38,7 +33,7 @@ VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7001'
# VITE_APP_BASE_API_Url = 'http://25.18.122.66:9786'
# h5专用地址x2
-# VITE_APP_BASE_H5_API_Url_TRAAPP = 'http://25.64.32.150:9601'
+#VITE_APP_BASE_H5_API_Url = 'http://25.64.32.157:9601'
# dev
#VITE_APP_BASE_H5_API_Url = 'http://25.18.122.65:7001'
@@ -53,5 +48,7 @@ VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7001'
# VITE_APP_BASE_H5_API_Url_TRAASK = 'http://25.64.16.144:9605'
# VITE_APP_BASE_H5_API_Url_TRAEXAM = 'http://25.64.16.154:9604'
+VITE_APP_BASE_H5_API_Url_TRAPRACTICE = 'http://25.64.32.157:9603'
+
diff --git a/src/pages/sparring/components/talk-list.vue b/src/pages/sparring/components/talk-list.vue
index dbac92e5..93e12fc6 100644
--- a/src/pages/sparring/components/talk-list.vue
+++ b/src/pages/sparring/components/talk-list.vue
@@ -1,84 +1,164 @@
-
-
-
-
-
-
-
-
- {{ talkList }}
+
+
+
+
+
+ {{ talkTextList }}
+
-
-
- 回答提示
+
+ 回答提示
+
+
+
+
+ {{ talkTipList }}
+
+
+
+
diff --git a/src/pages/sparring/js/ProtocolCodec.ts b/src/pages/sparring/js/ProtocolCodec.ts
index 60193a79..fac5f3e5 100644
--- a/src/pages/sparring/js/ProtocolCodec.ts
+++ b/src/pages/sparring/js/ProtocolCodec.ts
@@ -36,6 +36,36 @@ export enum MessageType {
// 预留12种类型用于扩展(0b0100 ~ 0b1111)
}
+/**
+ * 控制消息枚举
+ * 二进制标识,统一编码风格
+ */
+export enum ControlCode {
+ FINISH_PUSH = 0b0001, // 本轮tts推流结束
+ FINISH_PLAY = 0b0010, // 语音播放结束(发后端)
+ AI_ANSWER_BEGIN = 0b0011, // 本轮AI回答的文本内容开始
+ AI_ANSWER_OVER = 0b0100, // 本轮AI回答的文本内容已经全部返回
+ AI_CLUE = 0b0101, // 需要AI提示命令(发后端)
+ AI_CLUE_OVER = 0b0110, // AI提示命令已经全部返回
+}
+
+
+
+/**
+ * 错误类型枚举
+ * 二进制标识,统一编码风格
+ */
+export enum ErrorType {
+ PING = 2, // 认证错误
+ AUDIO_DATA = 0b0010, // 纯音频数据
+ TEXT_MESSAGE = 0b0011, // 大模型回复的文本消息
+ CONTROL_CMD = 0b0100, // 控制指令
+ IDENTITY = 0b0101, // 身份校验包json格式
+ ERROR = 0b0110, // 错误信息json格式
+ TIP_MESSAGE = 0b0111 // 大模型生成的回答提示
+ // 预留12种类型用于扩展(0b0100 ~ 0b1111)
+}
+
/**
* 序列化方式枚举(3位,存储在字节1高3位,1~8范围)
* 二进制标识,统一编码风格(1~8对应0b001~0b111)
diff --git a/src/pages/sparring/js/useWebSocket.js b/src/pages/sparring/js/useWebSocket.js
index 08b5af4c..d5f890b7 100644
--- a/src/pages/sparring/js/useWebSocket.js
+++ b/src/pages/sparring/js/useWebSocket.js
@@ -13,6 +13,7 @@ import {
import {
ProtocolCodec,
MessageType,
+ ControlCode,
SerializationType,
CompressionType,
ControlCommand,
@@ -31,9 +32,12 @@ export default function useWebSocket(aaas = null, options = {}) {
const isRecording = ref(false) //是否接通
const ws = ref(null)
const initConnection = ({
- authParams = {},
- onStartRecord,
- playPcmCallback,
+ authParams = {}, // 认证信息
+ onStartRecord, // 连接成功启动录音方法
+ playPcmCallback, // 播放返回音频的方法
+ addTalkText, // 显示返回的文字的方法
+ addTalkTip, // 显示返回的文字提示的方法
+ ctrlTalk, // 控制展示数据组件
setPlayNumber = () => {}, //设置当前播放的音频的id,用于播放完成回调
onError = () => {},
onClose = () => {},
@@ -83,51 +87,51 @@ export default function useWebSocket(aaas = null, options = {}) {
playPcmCallback(numArray)
break;
case MessageType.ERROR:
- switch (body.errCode) {
- case 1:
- // ASR或TTS初始化出错
- console.log('后端返回的错误', body.errMsg);
- case 4:
- console.log('通话接通失败', body.errMsg);
- // 通话接通失败,请稍后再试!
- ws.value.close({
- code: 4001,
- reason: '当前服务器繁忙,请稍后在试!'
- })
- onClose({
- code: 4001,
- reason: '当前服务器繁忙,请稍后在试!'
- })
- break;
- case 5: // 使用人数过多等其他错误
- ws.value.close({
- code: 4001,
- reason: body.errMsg
- })
- break;
- default:
- console.log('其他错误码的默认处理', body);
- // 其他错误码的默认处理(如果需要)
- // ws.value.close({
- // code: 1001,
- // reason: body.errMsg
- // })
- break;
+ if([1,2,4].includes(body.errCode)) {
+ // 1 ASR或TTS初始化出错
+ // 2 认证错误
+ // 4 通话接通失败,请稍后再试!
+ console.error('后端返回的错误码:', body.errCode, '错误消息:',body.errMsg);
+ error = {
+ code: 4001,
+ reason: '当前服务器繁忙,请稍后在试!'
+ }
+ ws.value.close(error)
+ onClose(error)
+ } else if(body.errCode === 5) {
+ // 5 使用人数过多等其他错误
+ ws.value.close({
+ code: 4001,
+ reason: body.errMsg
+ })
+ } else {
+ console.error('其他错误码的默认处理', body);
}
break;
case MessageType.CONTROL_CMD:
// 控制消息
- console.log('控制消息', msgType, body);
- if (body.type === 1) { // 开始播放,记录当前播放的语音id
+ console.log('控制消息', body, body.type === ControlCode.AI_ANSWER_BEGIN);
+ console.log('控制消息2', ControlCode.AI_ANSWER_BEGIN);
+
+ if (body.type === ControlCode.FINISH_PUSH) { // 开始播放,记录当前播放的语音id
console.log('开始播放,记录当前播放的语音id', body.lock);
setPlayNumber(body.lock)
+ } else if (body.type === ControlCode.AI_ANSWER_BEGIN) {
+ console.log('新一段对话内容来了');
+ ctrlTalk('textStart') // 新一段对话内容来了
+ } else if (body.type === ControlCode.AI_ANSWER_OVER) {
+ console.log('新一段对话结束了');
+ ctrlTalk('textEnd') // 新一段对话内容来了
}
break;
case MessageType.TEXT_MESSAGE:
console.log('TEXT_MESSAGE', body);
+ addTalkText(body)
+ break;
+ case MessageType.TIP_MESSAGE:
+ console.log('消息提示', body);
+ addTalkTip(body)
break;
-
-
default:
console.log('其他消息', msgType, body);
break;
diff --git a/src/pages/sparring/talk.vue b/src/pages/sparring/talk.vue
index dc817b9d..aeb5ad80 100644
--- a/src/pages/sparring/talk.vue
+++ b/src/pages/sparring/talk.vue
@@ -36,7 +36,7 @@
style="width: 240rpx; height: 360rpx; position: absolute; left: 0; top: 0"
>
-
+
@@ -44,9 +44,9 @@