Skip to content

feat: add autoReplace support for sender and update voice button document#315

Open
SonyLeo wants to merge 3 commits intoopentiny:developfrom
SonyLeo:docs/update-speech-config
Open

feat: add autoReplace support for sender and update voice button document#315
SonyLeo wants to merge 3 commits intoopentiny:developfrom
SonyLeo:docs/update-speech-config

Conversation

@SonyLeo
Copy link
Collaborator

@SonyLeo SonyLeo commented Mar 18, 2026

  • 补充并实现 autoReplace 功能
  • 更新 voice-input 案例说明
  • 更新文档相关说明、补充相关的内容

Summary by CodeRabbit

  • New Features

    • Enhanced voice input with append/replace modes for improved transcript control.
    • Added real-time transcript replacement capability during recording sessions.
  • Documentation

    • Updated voice recognition documentation with clearer language configuration guidance.
    • Improved speech configuration and voice button integration examples.

@coderabbitai
Copy link

coderabbitai bot commented Mar 18, 2026

Walkthrough

The pull request updates the voice input recognition system, changing the mode paradigm from mixed|continuous to append|replace. It implements real-time transcript insertion via an autoReplace mechanism in the VoiceButton component, removes the onVoiceButtonClick callback from the SpeechConfig interface, and updates related documentation with improved type signatures and configuration guidance.

Changes

Cohort / File(s) Summary
Documentation & Demo Updates
docs/demos/sender/voice-input.vue, docs/src/components/sender.md
Updated voice mode state options from `mixed
Voice Button Component
packages/components/src/sender-actions/voice-button/index.vue, packages/components/src/sender-actions/voice-button/speech.types.ts
Implemented speechRange state tracking and insertTranscript() helper to manage real-time transcript insertion. Updated speech lifecycle handlers to conditionally insert transcripts on onInterim when autoReplace is enabled, and on onFinal when disabled. Removed onVoiceButtonClick callback from SpeechConfig interface.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant Button as VoiceButton
    participant Speech as Speech Engine
    participant Editor as Editor/Document

    rect rgba(255, 200, 100, 0.5)
    Note over User,Editor: Old Flow: Final-Only Insertion
    User->>Button: Click to record
    Button->>Speech: Start recognition
    Speech-->>Button: onInterim (transcript update)
    Button->>Button: Emit interim event only
    Speech-->>Button: onFinal (final transcript)
    Button->>Editor: Insert transcript (if autoInsert)
    Button->>Editor: Focus editor
    end

    rect rgba(100, 200, 255, 0.5)
    Note over User,Editor: New Flow: Real-Time autoReplace Mode
    User->>Button: Click to record
    Button->>Speech: Start recognition (autoReplace: true)
    Speech-->>Button: onInterim (transcript update)
    Button->>Button: insertTranscript() with speechRange
    Button->>Editor: Replace text from position 0 to N
    Button->>Button: Update speechRange end position
    Speech-->>Button: onInterim (refined transcript)
    Button->>Editor: Replace text from position 0 to M
    Button->>Button: Update speechRange end position
    Speech-->>Button: onFinal (final transcript)
    Button->>Button: Reset speechRange, skip insertion
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A whispered hop through words so clear,
Now append and replace bring cheer,
Real-time transcripts take their flight,
With autoReplace shining bright!
The voice flows smoothly, what delight!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: implementing autoReplace support and updating voice button documentation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

✅ Preview build completed successfully!

Click the image above to preview.
Preview will be automatically removed when this PR is closed.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 18, 2026

@SonyLeo SonyLeo linked an issue Mar 18, 2026 that may be closed by this pull request
@SonyLeo SonyLeo force-pushed the docs/update-speech-config branch from 4c60cae to 855ae9e Compare March 18, 2026 09:25
@SonyLeo SonyLeo marked this pull request as ready for review March 20, 2026 06:50
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/components/src/sender-actions/voice-button/index.vue (1)

25-57: Consider simplifying speechRange state.

The speechRange.to field is tracked (line 54) but never read—the replacement always uses docSize as the end position. Since from is always 0 for autoReplace mode, you could simplify to just a boolean flag indicating whether a recording session has started.

However, if this tracking is intentional for future features (e.g., partial replacement from cursor position), feel free to keep it.

♻️ Optional simplification
-const speechRange = ref<{ from: number; to: number } | null>(null)
+const hasStartedRecording = ref(false)

 const resetSpeechRange = () => {
-  speechRange.value = null
+  hasStartedRecording.value = false
 }

 const insertTranscript = (transcript: string) => {
   // ... early returns ...
   
   // autoReplace 模式:替换整个输入框内容
-  if (speechRange.value === null) {
-    speechRange.value = {
-      from: 0,
-      to: 0,
-    }
-  }
+  hasStartedRecording.value = true

   const docSize = editorInstance.state.doc.content.size
-  const tr = editorInstance.state.tr.insertText(transcript, speechRange.value.from, docSize)
+  const tr = editorInstance.state.tr.insertText(transcript, 0, docSize)
   editorInstance.view.dispatch(tr)

-  speechRange.value = {
-    from: speechRange.value.from,
-    to: speechRange.value.from + transcript.length,
-  }
   editorInstance.commands.focus('end')
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/components/src/sender-actions/voice-button/index.vue` around lines
25 - 57, The speechRange.to field is never read in insertTranscript (autoReplace
uses docSize), so simplify state by removing speechRange.to and either replace
speechRange with a boolean like speechStarted or keep only speechRange.from;
update insertTranscript to initialize and check that flag (e.g., speechStarted
or speechRange.from === 0) and use speechRange.from (or 0) as the insert start,
and update the single state field accordingly; ensure references to
speechRange.value.to are removed and editorInstance, autoReplace, and
insertTranscript behavior remain unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@docs/src/components/sender.md`:
- Line 1: The file docs/src/components/sender.md contains a UTF-8 BOM (U+FEFF)
at the start; remove the BOM so the file begins with the first markdown
character and re-save the file as UTF-8 without BOM (e.g., strip the leading
U+FEFF or re-encode), ensuring consistency with speech.types.ts which was
corrected earlier.

In `@packages/components/src/sender-actions/voice-button/speech.types.ts`:
- Line 1: The file speech.types.ts contains a UTF‑8 BOM at the very start;
remove the leading BOM character so the file begins with the first TypeScript
token, re-save the file as UTF‑8 without BOM, and re-commit; if your editor adds
BOMs automatically, update its save settings (or run a one-time clean-up
command) to ensure speech.types.ts stays UTF‑8 without BOM.

---

Nitpick comments:
In `@packages/components/src/sender-actions/voice-button/index.vue`:
- Around line 25-57: The speechRange.to field is never read in insertTranscript
(autoReplace uses docSize), so simplify state by removing speechRange.to and
either replace speechRange with a boolean like speechStarted or keep only
speechRange.from; update insertTranscript to initialize and check that flag
(e.g., speechStarted or speechRange.from === 0) and use speechRange.from (or 0)
as the insert start, and update the single state field accordingly; ensure
references to speechRange.value.to are removed and editorInstance, autoReplace,
and insertTranscript behavior remain unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cc096f6e-f1c4-4f6d-b278-1a831a223417

📥 Commits

Reviewing files that changed from the base of the PR and between 16fd9bf and 855ae9e.

📒 Files selected for processing (4)
  • docs/demos/sender/voice-input.vue
  • docs/src/components/sender.md
  • packages/components/src/sender-actions/voice-button/index.vue
  • packages/components/src/sender-actions/voice-button/speech.types.ts

@@ -1,4 +1,4 @@
---
---
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

UTF-8 BOM character detected at file start.

Similar to speech.types.ts, this file has a UTF-8 BOM at the start. Consider removing it for consistency.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/src/components/sender.md` at line 1, The file
docs/src/components/sender.md contains a UTF-8 BOM (U+FEFF) at the start; remove
the BOM so the file begins with the first markdown character and re-save the
file as UTF-8 without BOM (e.g., strip the leading U+FEFF or re-encode),
ensuring consistency with speech.types.ts which was corrected earlier.

@@ -1,4 +1,4 @@
/**
/**
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

UTF-8 BOM character detected at file start.

The file begins with a UTF-8 BOM (), which is unusual for TypeScript files and may cause issues with some tools or editors. Consider removing it.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/components/src/sender-actions/voice-button/speech.types.ts` at line
1, The file speech.types.ts contains a UTF‑8 BOM at the very start; remove the
leading BOM character so the file begins with the first TypeScript token,
re-save the file as UTF‑8 without BOM, and re-commit; if your editor adds BOMs
automatically, update its save settings (or run a one-time clean-up command) to
ensure speech.types.ts stays UTF‑8 without BOM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【docs enhancement】speech config default lang

1 participant