x
This commit is contained in:
@@ -8,10 +8,19 @@
|
||||
@onStop="stopIt">
|
||||
</yao-RecordFrame>
|
||||
<sdx-StreamPlayer ref="aaa">xx</sdx-StreamPlayer>
|
||||
<button @click="test">测试</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
ProtocolCodec,
|
||||
MessageType,
|
||||
SerializationType,
|
||||
CompressionType,
|
||||
ControlCommand,
|
||||
ProtocolConst,
|
||||
} from './ProtocolCodec'; // 确保协议文件也是 ESModule 格式(export 导出)
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@@ -32,7 +41,10 @@
|
||||
},
|
||||
methods: {
|
||||
|
||||
|
||||
test() {
|
||||
|
||||
|
||||
},
|
||||
// 申请录音权限
|
||||
async applyRecordPermission() {
|
||||
try {
|
||||
@@ -55,16 +67,16 @@
|
||||
// ArrayBuffer 转字符串
|
||||
// 兼容的 ArrayBuffer 转字符串方法
|
||||
arrayBufferToStringCompat(buffer) {
|
||||
// 方法1: 使用 String.fromCharCode 和 Uint8Array
|
||||
const uint8Array = new Uint8Array(buffer);
|
||||
let str = '';
|
||||
for (let i = 0; i < uint8Array.length; i++) {
|
||||
str += String.fromCharCode(uint8Array[i]);
|
||||
}
|
||||
return str;
|
||||
|
||||
// 方法2: 或者使用更简洁的方式
|
||||
// return String.fromCharCode.apply(null, new Uint8Array(buffer));
|
||||
// 方法1: 使用 String.fromCharCode 和 Uint8Array
|
||||
const uint8Array = new Uint8Array(buffer);
|
||||
let str = '';
|
||||
for (let i = 0; i < uint8Array.length; i++) {
|
||||
str += String.fromCharCode(uint8Array[i]);
|
||||
}
|
||||
return str;
|
||||
|
||||
// 方法2: 或者使用更简洁的方式
|
||||
// return String.fromCharCode.apply(null, new Uint8Array(buffer));
|
||||
},
|
||||
// 开始录音
|
||||
async onStartRecord() {
|
||||
@@ -80,7 +92,7 @@
|
||||
console.log('web');
|
||||
this.ws.onOpen((res) => {
|
||||
console.log('WebSocket连接已打开', res);
|
||||
|
||||
|
||||
|
||||
this.ws.onMessage((res) => {
|
||||
let messageData = res.data;
|
||||
@@ -99,7 +111,7 @@
|
||||
this.$refs.aaa.appendBuffer(messageData)
|
||||
// const str = this.arrayBufferToStringCompat(messageData);
|
||||
// console.log('转换后的字符串:', str);
|
||||
|
||||
|
||||
} catch (e) {
|
||||
console.log('二进制数据解析失败:', e);
|
||||
}
|
||||
@@ -127,7 +139,7 @@
|
||||
// 处理帧数据(如实时上传/渲染)
|
||||
// console.log('帧数据:', frameData);
|
||||
this.ws.send({
|
||||
data: frameBuffer
|
||||
data: ProtocolCodec.pack(MessageType.AUDIO_DATA, frameBuffer);
|
||||
});
|
||||
},
|
||||
onDecibels: (decibels) => {
|
||||
@@ -144,7 +156,7 @@
|
||||
this.isRecording = false;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
// 停止录音
|
||||
onStopRecord() {
|
||||
this.stopRecordAndClean();
|
||||
|
||||
Reference in New Issue
Block a user