From 71b70421fc55f927c828c92cd34829fb317ff7b1 Mon Sep 17 00:00:00 2001 From: SonyLeo <746591437@qq.com> Date: Tue, 17 Mar 2026 06:22:14 -0700 Subject: [PATCH 1/3] feat(voice-button): add autoReplace support for continuous speech replacement --- docs/src/components/sender.md | 19 ++++++-- .../src/sender-actions/voice-button/index.vue | 47 +++++++++++++++---- .../voice-button/speech.types.ts | 2 +- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/docs/src/components/sender.md b/docs/src/components/sender.md index e78fb9d9c..c72ae693f 100644 --- a/docs/src/components/sender.md +++ b/docs/src/components/sender.md @@ -155,10 +155,23 @@ TrSender.Suggestion.configure({ items: suggestions, filterFn: customFilter }) #### 基础语音识别 -使用浏览器内置的语音识别功能,支持混合输入和连续识别两种模式。 +使用浏览器内置的语音识别功能,支持混合输入和连续识别两种模式。可通过 `speechConfig.lang` 显式指定识别语言。 +:::tip lang 语言说明 +`lang` 用于指定语音识别语言,建议显式传入,并与页面的 `html lang` 保持一致,避免页面语言和浏览器环境语言不一致时出现识别偏差。 + +常见取值示例: + +| 值 | 说明 | +| --- | --- | +| `en` | 英语 | +| `zh` | 中文 | +| `zh-CN` | 简体中文 | +| `en-US` | 美式英语 | +::: + #### 自定义语音服务 支持集成第三方语音识别服务(如阿里云、百度、Azure 等)。 @@ -597,7 +610,7 @@ type TooltipPlacement = // SpeechConfig 语音配置 interface SpeechConfig { customHandler?: SpeechHandler // 自定义语音处理器 - lang?: string // 识别语言,默认浏览器语言 + lang?: string // 识别语言,建议显式配置并与 html lang 保持一致;未传入时由浏览器环境决定 continuous?: boolean // 是否持续识别 interimResults?: boolean // 是否返回中间结果 autoReplace?: boolean // 是否自动替换内容 @@ -789,4 +802,4 @@ Sender 组件提供了丰富的 CSS 变量用于自定义样式。 |-------|----------| | startSpeech | 使用 `VoiceButton.start()` | | stopSpeech | 使用 `VoiceButton.stop()` | -| activateTemplateFirstField | 自动处理,无需调用 | \ No newline at end of file +| activateTemplateFirstField | 自动处理,无需调用 | diff --git a/packages/components/src/sender-actions/voice-button/index.vue b/packages/components/src/sender-actions/voice-button/index.vue index 700bb5200..1cd7d5f84 100644 --- a/packages/components/src/sender-actions/voice-button/index.vue +++ b/packages/components/src/sender-actions/voice-button/index.vue @@ -1,5 +1,5 @@