Refactor ASR module and remove deprecated AliAsrServer

- Introduced AsrRelatime class for real-time ASR using WebSocket.
- Removed AliAsrServer and related files from the aliyun provider.
- Updated base class for ASR to use WSServer for WebSocket connections.
- Added new test cases for the updated ASR functionality.
- Cleaned up unused imports and files across the project.
- Adjusted TypeScript configuration for better module resolution.
- Implemented silence generation for audio streaming.
This commit is contained in:
2025-12-21 18:56:32 +08:00
parent 9e94a4d898
commit 58b27b86fe
20 changed files with 858 additions and 3626 deletions

42
src/ws/index.ts Normal file
View File

@@ -0,0 +1,42 @@
const isBrowser = (typeof process === 'undefined') ||
(typeof window !== 'undefined' && typeof window.document !== 'undefined') ||
(typeof process !== 'undefined' && process?.env?.BROWSER === 'true');
const chantHttpToWs = (url: string) => {
if (url.startsWith('http://')) {
return url.replace('http://', 'ws://');
}
if (url.startsWith('https://')) {
return url.replace('https://', 'wss://');
}
return url;
};
type WebSocketOptions = {
/**
* 是否拒绝不安全的证书, in node only
*/
rejectUnauthorized?: boolean;
headers?: Record<string, string>;
[key: string]: any;
};
export const initWs = async (url: string, options?: WebSocketOptions) => {
let ws: WebSocket;
url = chantHttpToWs(url);
if (isBrowser) {
ws = new WebSocket(url);
} else {
const WebSocket = await import('ws').then((module) => module.default);
const { rejectUnauthorized, headers, ...rest } = options || {};
ws = new WebSocket(url, {
rejectUnauthorized: rejectUnauthorized ?? true,
headers: headers,
...rest,
}) as any;
}
return ws;
};
export interface EventEmitterOptions {
/**
* Enables automatic capturing of promise rejection.
*/
captureRejections?: boolean | undefined;
}