x
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
CompressionType,
|
||||
ControlCommand,
|
||||
ProtocolConst,
|
||||
} from './ProtocolCodec'; // 确保协议文件也是 ESModule 格式(export 导出)
|
||||
} from './ProtocolCodec';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@@ -32,7 +32,9 @@
|
||||
scriptProcessor: null, // 音频处理节点
|
||||
audioBufferSource: null, // 音频源节点
|
||||
frameBufferList: [], // 缓存音频帧
|
||||
wsUrl: "ws://127.0.0.1:8000/ws/audio", // 替换为实际后端地址
|
||||
// wsUrl: "ws://127.0.0.1:8000/ws/audio", // 替换为实际后端地址
|
||||
wsUrl: "ws://172.16.89.58:8000/ws/audio", // 替换为实际后端地址
|
||||
// wsUrl: "ws://25.64.32.157:9603/trapractice/voiceCallSocket/voiceCall?summary=3D072C9D242C96EA3F0FD647CB14A6F4B4BEA4493BB2FAAB065935FB405071B8A903128E488B6D06BEB23FD4E3D15EE6", // 替换为实际后端地址
|
||||
};
|
||||
},
|
||||
onUnload() {
|
||||
@@ -40,7 +42,6 @@
|
||||
this.stopRecordAndClean();
|
||||
},
|
||||
methods: {
|
||||
|
||||
test() {
|
||||
this.ws = uni.connectSocket({
|
||||
url: this.wsUrl,
|
||||
@@ -49,7 +50,6 @@
|
||||
},
|
||||
success: () => {
|
||||
console.log('web');
|
||||
|
||||
},
|
||||
fail: () => {
|
||||
console.log('fail');
|
||||
@@ -70,32 +70,14 @@
|
||||
msgType,
|
||||
body
|
||||
} = ProtocolCodec.unpack(res.data)
|
||||
|
||||
if (msgType === MessageType.IDENTITY) {
|
||||
if (body?.code === 200) {
|
||||
console.log('身份校验成功');
|
||||
}
|
||||
console.log('身份校验成功', body);
|
||||
this.onStartRecord()
|
||||
} else if (msgType === MessageType.AUDIO_DATA) {
|
||||
this.$refs.aaa.appendBuffer(body)
|
||||
}
|
||||
// 处理不同类型的数据
|
||||
// if (typeof messageData === 'string') {
|
||||
// // 文本数据
|
||||
// try {
|
||||
// const parsedData = JSON.parse(messageData);
|
||||
// this.handleMessage(parsedData);
|
||||
// } catch (e) {
|
||||
// this.handleMessage(messageData);
|
||||
// }
|
||||
// } else if (messageData instanceof ArrayBuffer) {
|
||||
// // 二进制数据
|
||||
// try {
|
||||
// this.$refs.aaa.appendBuffer(messageData)
|
||||
// // const str = this.arrayBufferToStringCompat(messageData);
|
||||
// // console.log('转换后的字符串:', str);
|
||||
|
||||
// } catch (e) {
|
||||
// console.log('二进制数据解析失败:', e);
|
||||
// }
|
||||
// }
|
||||
|
||||
})
|
||||
|
||||
},
|
||||
@@ -134,7 +116,7 @@
|
||||
},
|
||||
// 开始录音
|
||||
onStartRecord() {
|
||||
|
||||
console.log('开始录音');
|
||||
try {
|
||||
this.$refs.recordFrame.start({
|
||||
sampleRate: 16000,
|
||||
@@ -144,9 +126,11 @@
|
||||
isLastFrame,
|
||||
frameBuffer
|
||||
}) => {
|
||||
this.ws.send({
|
||||
data: ProtocolCodec.pack(MessageType.AUDIO_DATA, frameBuffer)
|
||||
});
|
||||
try{
|
||||
this.ws.send({
|
||||
data: ProtocolCodec.pack(MessageType.AUDIO_DATA, frameBuffer)
|
||||
});
|
||||
} catch(e){}
|
||||
},
|
||||
onDecibels: (decibels) => {
|
||||
this.currentDecibels = decibels;
|
||||
|
||||
Reference in New Issue
Block a user