From b79f5bcfc5c06dfc8eea9828f2199ff59087caa3 Mon Sep 17 00:00:00 2001 From: "quemingyi.wudong" Date: Thu, 3 Apr 2025 14:15:53 +0800 Subject: [PATCH] fix: fix aiAns Extension & distinguish asr large/small model configurations & remove linebreak eslint. --- .eslintrc | 2 +- src/config/config.ts | 35 +++++++++++++++++++++++++---------- src/lib/RtcClient.ts | 3 +-- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/.eslintrc b/.eslintrc index ce60216..f13c040 100644 --- a/.eslintrc +++ b/.eslintrc @@ -42,7 +42,7 @@ ], "rules": { "prettier/prettier": ["warn", { "trailingComma": "es5", "printWidth": 200 }], - "linebreak-style": ["error", "unix"], + "linebreak-style": "off", "no-console": ["warn", { "allow": ["warn", "error", "log"] }], "no-case-declarations": 0, "no-param-reassign": 0, diff --git a/src/config/config.ts b/src/config/config.ts index 24d6719..b2deb45 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -72,7 +72,9 @@ export class ConfigFactory { ASRAppId: 'Your ASR AppId', /** * @brief 已开通流式语音识别大模型服务 AppId 对应的 Access Token。 - * 使用流式语音识别大模型服务时该参数为 必填。 + * @note 使用流式语音识别 **大模型** 服务时必填, 可于 https://console.volcengine.com/speech/service/10011?AppID=6482372612&s=g 中查看。 + * 注意, 如果填写了 ASRToken, Demo 会默认使用大模型模式,请留意相关资源是否已经开通。 + * 默认为使用小模型,无需配置 ASRToken。 */ ASRToken: undefined, }; @@ -156,13 +158,13 @@ export class ConfigFactory { } get ASRConfig() { - const params: Record = { + /** + * @brief SmallModelASRConfigs 为小模型的配置 + * @note 本示例代码使用的是小模型语音识别, 如感觉 ASR 效果不佳,可尝试使用大模型进行语音识别。 + */ + const SmallModelASRConfigs = { Provider: 'volcano', ProviderParams: { - /** - * @note 本示例代码使用的是小模型语音识别, 如感觉 ASR 效果不佳,可尝试使用大模型进行语音识别。 - * 大模型的使用详情可参考 https://www.volcengine.com/docs/6348/1404673#volcanolmasrconfig?s=g - */ Mode: 'smallmodel', AppId: this.BaseConfig.ASRAppId, /** @@ -171,16 +173,29 @@ export class ConfigFactory { */ Cluster: 'volcengine_streaming_common', }, + /** + * @note 小模型情况下, 建议使用 VAD 及音量采集设置, 以优化识别效果。 + */ VADConfig: { SilenceTime: 600, SilenceThreshold: 200, }, VolumeGain: 0.3, }; - if (this.BaseConfig.ASRToken) { - params.ProviderParams.AccessToken = this.BaseConfig.ASRToken; - } - return params; + + /** + * @brief BigModelASRConfigs 为大模型的配置 + * @note 大模型的使用详情可参考 https://www.volcengine.com/docs/6348/1404673#volcanolmasrconfig?s=g + */ + const BigModelASRConfigs = { + Provider: 'volcano', + ProviderParams: { + Mode: 'bigmodel', + AppId: this.BaseConfig.ASRAppId, + AccessToken: this.BaseConfig.ASRToken, + }, + }; + return this.BaseConfig.ASRToken ? BigModelASRConfigs : SmallModelASRConfigs; } get TTSConfig() { diff --git a/src/lib/RtcClient.ts b/src/lib/RtcClient.ts index b1fe23f..c6905fe 100644 --- a/src/lib/RtcClient.ts +++ b/src/lib/RtcClient.ts @@ -70,8 +70,6 @@ export interface BasicBody { login_token: string | null; } -export const AIAnsExtension = new RTCAIAnsExtension(); - /** * @brief RTC Core Client * @notes Refer to official website documentation to get more information about the API. @@ -101,6 +99,7 @@ export class RTCClient { this.engine = VERTC.createEngine(this.config.appId); try { + const AIAnsExtension = new RTCAIAnsExtension(); await this.engine.registerExtension(AIAnsExtension); AIAnsExtension.enable(); } catch (error) {