update add asr config
This commit is contained in:
@@ -130,7 +130,7 @@ export type AssistantConfigData = {
|
|||||||
*/
|
*/
|
||||||
home?: string;
|
home?: string;
|
||||||
/**
|
/**
|
||||||
* 启用本地AI代理
|
* 启用AI代理
|
||||||
*/
|
*/
|
||||||
ai?: {
|
ai?: {
|
||||||
enabled?: boolean;
|
enabled?: boolean;
|
||||||
@@ -138,6 +138,11 @@ export type AssistantConfigData = {
|
|||||||
apiKey?: string;
|
apiKey?: string;
|
||||||
model?: string;
|
model?: string;
|
||||||
};
|
};
|
||||||
|
/** 阿里云的语音识别服务,模型 qwen3-asr-flash-realtime */
|
||||||
|
asr?: {
|
||||||
|
enabled?: boolean;
|
||||||
|
token?: string;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 自定义脚本, asst 启动时会执行这些脚本
|
* 自定义脚本, asst 启动时会执行这些脚本
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { QwenAsrRelatime } from "@kevisual/video-tools/src/asr/index.ts";
|
|||||||
|
|
||||||
import { Listener, WebSocketListenerFun, WebSocketReq } from "@kevisual/router";
|
import { Listener, WebSocketListenerFun, WebSocketReq } from "@kevisual/router";
|
||||||
import { lightHA } from "@/routes/ha-api/ha.ts";
|
import { lightHA } from "@/routes/ha-api/ha.ts";
|
||||||
|
import { assistantConfig } from "@/app.ts";
|
||||||
|
|
||||||
const func: WebSocketListenerFun = async (req: WebSocketReq<{ asr: QwenAsrRelatime, msgId: string, startTime?: number }>, res) => {
|
const func: WebSocketListenerFun = async (req: WebSocketReq<{ asr: QwenAsrRelatime, msgId: string, startTime?: number }>, res) => {
|
||||||
const { ws, emitter, id, data } = req;
|
const { ws, emitter, id, data } = req;
|
||||||
@@ -13,7 +14,19 @@ const func: WebSocketListenerFun = async (req: WebSocketReq<{ asr: QwenAsrRelati
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!asr) {
|
if (!asr) {
|
||||||
const token = process.env.BAILIAN_API_KEY || ''
|
const confg = assistantConfig.getConfig();
|
||||||
|
const asrConfig = confg?.asr;
|
||||||
|
if (!asrConfig?.enabled) {
|
||||||
|
ws.send(JSON.stringify({ type: 'error', message: 'asr服务未启用' }));
|
||||||
|
ws.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const token = asrConfig?.token;
|
||||||
|
if (!token) {
|
||||||
|
ws.send(JSON.stringify({ type: 'error', message: 'asr服务未配置token' }));
|
||||||
|
ws.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 第一次请求
|
// 第一次请求
|
||||||
asr = new QwenAsrRelatime({
|
asr = new QwenAsrRelatime({
|
||||||
token,
|
token,
|
||||||
|
|||||||
Reference in New Issue
Block a user