"feat: 更新ASR服务连接配置,优化录音流处理及模型路径"

This commit is contained in:
2025-06-02 12:38:53 +08:00
parent e638d7907a
commit 232d799575
8 changed files with 242 additions and 26 deletions

View File

@@ -5,22 +5,32 @@ import Stream from 'stream';
const recorder = new Recording();
const writeStream = new Stream.Writable();
const url = 'wss://funasr.xiongxiao.me';
const ws = new VideoWS({
url: 'wss://192.168.31.220:10095',
// url: 'wss://192.168.31.220:10095',
url: url,
isFile: false,
mode: '2pass',
wsOptions: {
rejectUnauthorized: false,
},
onConnect: async () => {
console.log('onConnect');
recorder.start();
let chunks: Buffer = Buffer.alloc(0);
var chunk_size = 960; // for asr chunk_size [5, 10, 5]
let totalsend = 0;
let len = 0;
recorder.stream().on('data', (chunk) => {
chunks = Buffer.concat([chunks, chunk]);
if (chunks.length > chunk_size) {
ws.send(chunks);
totalsend += chunks.length;
chunks = Buffer.alloc(0);
}
// chunks = Buffer.concat([chunks, chunk]);
// if (chunks.length > chunk_size) {
// ws.send(chunks);
// console.log('chunk', chunk.length);
// totalsend += chunks.length;
// chunks = Buffer.alloc(0);
// }
ws.send(chunk);
});
ws.start();
setTimeout(() => {
@@ -29,7 +39,11 @@ const ws = new VideoWS({
process.exit(0);
}, 1000);
console.log('len', len);
}, 20000);
}, 10 * 30 * 1000);
// }, 5 * 1000);
ws.emitter.on('message', (event) => {
// console.log('message', event.data);
});
},
});
@@ -38,4 +52,4 @@ const server = net.createServer((socket) => {
console.log('data', data);
});
});
server.listen(10096);
server.listen(10097);

View File

@@ -1,7 +1,7 @@
// import WebSocket from 'ws';
import { initWs } from '../../../ws-adapter/index.ts';
import { logger } from '@/logger/index.ts';
import { WSServer } from '../../provider/ws-server.ts';
import { WSServer, WSSOptions } from '../../provider/ws-server.ts';
export type VideoWSOptions = {
url?: string;
@@ -11,19 +11,30 @@ export type VideoWSOptions = {
isFile?: boolean;
onConnect?: () => void;
wav_format?: string;
} & {
wsOptions?: WSSOptions['wsOptions'];
};
export const videoWsMode = ['2pass', 'online', 'offline'] as const;
type VideoWsMode = (typeof videoWsMode)[number];
type OpenRequest = {
// 语音分片大小(单位: 毫秒):
chunk_size: number[];
// 音频文件名:
wav_name: string;
// 是否正在说话:
is_speaking: boolean;
// 分片间隔(单位: 毫秒):
chunk_interval: number;
// 逆文本标准化(ITN):
itn: boolean;
// 模式:
// '2pass' - 双通道模式, 'online' - 在线模式, 'offline' - 离线模式
mode: VideoWsMode;
// 音频格式:
wav_format?: string;
// 音频采样率(单位: Hz):
audio_fs?: number;
// 热词列表:
hotwords?: string;
};
export type VideoWsResult = {
@@ -40,7 +51,7 @@ export class VideoWS extends WSServer {
mode?: VideoWsMode;
wav_format?: string;
constructor(options?: VideoWSOptions) {
super({ url: options?.url, ws: options?.ws, onConnect: options?.onConnect });
super({ url: options?.url, ws: options?.ws, onConnect: options?.onConnect, wsOptions: options?.wsOptions });
this.itn = options?.itn || false;
this.itn = options?.itn || false;
this.mode = options?.mode || 'online';

View File

@@ -1,7 +1,7 @@
import { EventEmitter } from 'eventemitter3';
import { initWs } from '../../ws-adapter/index.ts';
import type { ClientOptions } from 'ws';
type WSSOptions = {
export type WSSOptions = {
url: string;
ws?: WebSocket;
onConnect?: () => void;