temp test

This commit is contained in:
2025-08-23 22:34:36 +08:00
parent e4596b4fde
commit 8047577165
3 changed files with 65 additions and 31 deletions

View File

@@ -60,7 +60,7 @@ export class VideoWS extends WSServer {
async start(opts?: Partial<OpenRequest>) {
const chunk_size = new Array(5, 10, 5);
console.log('start', chunk_size);
const request: OpenRequest = {
chunk_size: chunk_size,
wav_name: 'h5', //
@@ -94,15 +94,20 @@ export class VideoWS extends WSServer {
this.ws.send(data);
}
}
async sendBuffer(data: Buffer, opts?: { isFile?: boolean; wav_format?: string }) {
const { wav_format = 'wav' } = opts || {};
/**
* 发送音频数据, 离线
* @param data 音频数据
* @param opts 选项
*/
async sendBuffer(data: Buffer, opts?: { isFile?: boolean; wav_format?: string; online?: boolean }) {
const { wav_format = 'wav', online = false } = opts || {};
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
let sampleBuf = new Uint8Array(data);
const ws = this;
var chunk_size = 960; // for asr chunk_size [5, 10, 5]
let totalsend = 0;
let len = 0;
ws.start({ wav_format });
if (!online) ws.start({ wav_format });
while (sampleBuf.length >= chunk_size) {
const sendBuf = sampleBuf.slice(0, chunk_size);
totalsend = totalsend + sampleBuf.length;
@@ -111,7 +116,7 @@ export class VideoWS extends WSServer {
ws.send(sendBuf);
len++;
}
ws.stop();
if (!online) ws.stop();
}
}
async onMessage(event: MessageEvent) {