This commit is contained in:
2025-12-21 19:43:16 +08:00
parent a9ec22bef0
commit 00e91e8b28
3 changed files with 16 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@kevisual/video-tools", "name": "@kevisual/video-tools",
"version": "0.0.7", "version": "0.0.8",
"description": "", "description": "",
"main": "index.js", "main": "index.js",
"basename": "/root/video-tools", "basename": "/root/video-tools",

View File

@@ -115,6 +115,14 @@ export class AsrRelatime extends WSServer {
console.log('error', error); console.log('error', error);
} }
} }
async onClose(event: CloseEvent) {
let { code } = event;
if (code === 1007) {
// reason: Idle timeout
code = 0; // 超时不重连
}
super.onClose({ ...event, code });
}
async isEnd(type: string) { async isEnd(type: string) {
const types = ['conversation.item.input_audio_transcription.text', 'conversation.item.input_audio_transcription.completed']; const types = ['conversation.item.input_audio_transcription.text', 'conversation.item.input_audio_transcription.completed'];
if (type === types[1]) { if (type === types[1]) {

View File

@@ -24,18 +24,19 @@ async function main() {
}); });
ws.emitter.on('close', (event) => { ws.emitter.on('close', (event) => {
const { code, reason, type } = event || {}; const { code, reason, type } = event || {};
console.log('Connection closed:', code, reason, type); console.log('close envent', event);
console.log('Connection closed:', code)
if (typeof code === 'number' && code !== 0) { if (typeof code === 'number' && code !== 0) {
ws.reconnect({ timeout: 1000 }); ws.reconnect({ timeout: 1000 });
} }
}); });
await ws.start(); await ws.start();
const audioContent = await fs.readFile(videoTestPath); // const audioContent = await fs.readFile(videoTestPath);
ws.sendBuffer(audioContent); // ws.sendBuffer(audioContent);
ws.sendBlank(); // ws.sendBlank();
ws.sendBuffer(await fs.readFile(videoTestPath2)); // ws.sendBuffer(await fs.readFile(videoTestPath2));
ws.sendBlank(); // ws.sendBlank();
}, },
}); });