Skip to content

fix(asr): 修复 Windows 本地长语音只识别前段#769

Open
Duyi-Wang wants to merge 1 commit into
Open-Less:betafrom
Duyi-Wang:dev
Open

fix(asr): 修复 Windows 本地长语音只识别前段#769
Duyi-Wang wants to merge 1 commit into
Open-Less:betafrom
Duyi-Wang:dev

Conversation

@Duyi-Wang

@Duyi-Wang Duyi-Wang commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

User description

摘要

修复 Windows 本地 ASR 在长语音场景下可能只识别前一段的问题。

主要原因是 foundry-local-whisper 使用 Whisper 系模型,单次解码窗口约 30 秒;当录音超过这个窗口时,单次把整段 WAV 交给 Foundry SDK 可能只返回前段结果。这个 PR 将 Foundry Local Whisper 的 PCM 输入按 30 秒分片转写,再合并分片文本;同时把 Windows 本地 ASR 的转写超时从固定 30 秒改为按音频时长动态增长。

未关联 issue。

修复 / 新增 / 改进

  • foundry-local-whisper 录音结束后按 30 秒 PCM chunk 分片,逐段生成临时 WAV 并调用 Foundry SDK。
  • 复用 Whisper batch ASR 的 chunk split / transcript join 逻辑,避免中英文、CJK 标点拼接时产生明显断裂。
  • 为 Foundry / Sherpa provider 增加 buffer_duration_ms(),coordinator 可按实际录音长度计算 timeout。
  • 普通听写、QA、overlay QA、历史重新转录路径都接入 Windows 本地 ASR 动态 timeout。
  • 将 Windows Foundry / Sherpa 本地 ASR timeout 调整为 max(30s, ceil(audio_s) + 20s),避免长音频撞固定 30 秒超时。
  • 增加 Foundry 分片、buffer duration、Sherpa buffer duration、Windows 本地 ASR timeout 相关测试。

兼容

  • 不包含:

    • 云端 ASR 协议变更。
    • 录音采集链路变更。
    • 插入 / polish 流程变更。
    • 用户配置迁移或模型配置变更。
  • 对现有用户 / 本地环境 / 构建流程的影响:

    • 短语音仍使用 30 秒 timeout 保底,行为基本不变。
    • 长语音在 foundry-local-whisper 下会拆成多段本地识别,整体耗时会随音频长度增加,但可以覆盖完整录音。
    • sherpa-onnx-local 仅调整 timeout 预算,不改变识别输入和模型调用方式。

测试计划


PR Type

Bug fix, Enhancement


Description

  • Split Foundry Local Whisper PCM into 30s chunks for long audio

  • Add dynamic timeout based on actual audio duration for both Foundry and Sherpa

  • Reuse existing Whisper chunk split/join logic to avoid text gaps

  • Apply dynamic timeout across dictation, QA, overlay QA, and re-transcribe paths


Diagram Walkthrough

flowchart LR
  A["Audio PCM"] --> B["buffer_duration_ms()"]
  B --> C{"duration > 30s?"}
  C -- Yes --> D["split_pcm_by_duration(30s)"]
  D --> E["Transcribe each chunk separately"]
  E --> F["join_transcript_chunks()"]
  F --> G["Final transcript"]
  C -- No --> H["Transcribe whole audio"]
  H --> G
  B --> I["Calculate timeout: max(30, ceil(audio_secs)+20)"]
  I --> J["Set transcribe timeout"]
  J --> E
  J --> H
Loading

File Walkthrough

Relevant files
Enhancement
foundry_provider.rs
Implement PCM chunking for Foundry Local Whisper                 

openless-all/app/src-tauri/src/asr/local/foundry_provider.rs

  • Added FOUNDRY_WHISPER_CHUNK_LIMIT_MS constant (30s)
  • Added buffer_duration_ms() method to report buffered PCM duration
  • Modified transcribe() to split PCM into chunks and transcribe each
  • Added tests for chunk splitting and buffer duration
+73/-17 
sherpa_provider.rs
Add buffer duration reporting for Sherpa provider               

openless-all/app/src-tauri/src/asr/local/sherpa_provider.rs

  • Added buffer_duration_ms() method for both Offline and Online modes
  • Added test for buffer duration without consuming PCM
+25/-0   
coordinator.rs
Implement dynamic transcribe timeout for local ASR             

openless-all/app/src-tauri/src/coordinator.rs

  • Replaced fixed 30s timeout with dynamic
    foundry_audio_transcribe_timeout(audio_secs) and
    sherpa_audio_transcribe_timeout(audio_secs)
  • Added tests for new timeout functions
  • Updated ActiveAsr::FoundryLocalWhisper and SherpaOnnxLocal branches to
    use dynamic timeout
+43/-19 
Miscellaneous
whisper.rs
Make Whisper chunk utilities public                                           

openless-all/app/src-tauri/src/asr/whisper.rs

  • Made split_pcm_by_duration and join_transcript_chunks pub(crate) for
    reuse
+2/-2     
Bug fix
dictation.rs
Apply dynamic timeout to dictation end session                     

openless-all/app/src-tauri/src/coordinator/dictation.rs

  • Updated Foundry and Sherpa dictation end_session to compute dynamic
    timeout from buffer_duration_ms
  • Added logging for audio duration and timeout
+16/-8   
qa_session.rs
Apply dynamic timeout to QA and overlay dictation paths   

openless-all/app/src-tauri/src/coordinator/qa_session.rs

  • Updated overlay dictation and end QA session for Foundry/Sherpa to use
    dynamic timeout
  • Added logging for audio duration and timeout
+22/-16 

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant