Skip to content

fix(asr): 过滤 GLM-ASR 偶发的纯井号占位转写(#787) - #916

Merged
H-Chris233 merged 1 commit into
Open-Less:mainfrom
H-Chris233:codex/fix-zhipu-hash-placeholder
Aug 4, 2026
Merged

fix(asr): 过滤 GLM-ASR 偶发的纯井号占位转写(#787)#916
H-Chris233 merged 1 commit into
Open-Less:mainfrom
H-Chris233:codex/fix-zhipu-hash-placeholder

Conversation

@H-Chris233

@H-Chris233 H-Chris233 commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

User description

修复 issue #787:智谱 GLM-ASR 作为供应商时,静音/弱音片段偶发把整段识别为单个 #\(或 ##\…),当前 Whisper 兼容客户端仅 trim 后当作有效转写,导致占位符被插入用户输入。

改动

  • 在 \�sr/whisper.rs\ 新增 \is_placeholder_heading\:整段仅由 #\ 组成(#/##/###\…)即视为占位结果。
  • \WhisperBatchASR::transcribe_chunk\ 普通分支与 \�xtract_confident_text\ 回退分支均应用该判定,命中归一化为空转写。
  • 空转写自然进入既有空转写护栏(「没有识别到语音」+ emptyTranscript 历史),占位符不再落到输入框;多分片场景仅丢弃异常分片,\C#\、# 你好\ 等真实内容不受影响。

测试

新增 4 个单元测试(纯 #/##/### 归一化为空、混合分片丢弃占位、全占位整体为空、正常内容不受影响),\cargo test -p openless asr::whisper\ 33 个测试全部通过。


PR Type

Bug fix, Tests


Description

  • Filter GLM-ASR pure # placeholder transcriptions.

  • Normalize placeholder chunks to empty transcripts.

  • Add unit tests covering placeholder scenarios.

  • Guard real transcripts with other characters.


Diagram Walkthrough

flowchart LR
  A["ASR response text"] --> B{"is_placeholder_heading?"}
  B -- "yes" --> C["Empty transcript"]
  B -- "no" --> D["Normal transcript"]
  C --> E["Existing empty guard"]
Loading

File Walkthrough

Relevant files
Bug fix
whisper.rs
Filter pure hash placeholders in ASR transcriptions           

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

  • Added is_placeholder_heading helper for pure # text.
  • Applied empty normalization in transcribe_chunk and fallback.
  • Added tests for hash-only, mixed, and all-placeholder chunks.
  • Preserved real content like C# and # 你好.
+103/-2 

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

787 - PR Code Verified

Compliant requirements:

  • 非 verbose_json 分支对纯 '#' 文本归一化为空转写。
  • extract_confident_text 无 segments 回退分支同样对纯 '#' 归一化。
  • 空转写走既有护栏,占位符不会插入输入框。
  • 新增 4 个单元测试覆盖纯 '#/##/###'、混合分片丢弃、全占位为空、正常内容不受影响。

Requires further human verification:

  • 需要在实际 GLM-ASR 供应商上做端到端/UI 验证,确认多次语音输入不再出现 '#'。
  • 若 GLM-ASR 在 verbose_json 模式下会返回包含纯 '#' 文本的 segments,需确认现有 segments 置信度过滤是否仍会漏过;当前 filter 未在 segments 循环内应用。
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Coverage Gap

extract_confident_text only applies is_placeholder_heading in the no-segments fallback. If a verbose_json response contains a segment whose text is #/##, that segment can still be appended to kept and surface a placeholder unless the existing confidence filters happen to drop it. This is a coverage gap rather than a regression; it matters only if GLM-ASR can return such segments. Consider applying is_placeholder_heading per segment, or to the final joined text, to close this path.

let mut kept = String::new();
for seg in segments {
    let text = seg.get("text").and_then(|t| t.as_str()).unwrap_or("");
    if text.trim().is_empty() {
        continue;
    }
    let no_speech = seg
        .get("no_speech_prob")
        .and_then(|v| v.as_f64())
        .unwrap_or(0.0);
    let avg_logprob = seg
        .get("avg_logprob")
        .and_then(|v| v.as_f64())
        .unwrap_or(0.0);
    let compression = seg
        .get("compression_ratio")
        .and_then(|v| v.as_f64())
        .unwrap_or(1.0);

    let is_hallucination =
        (no_speech > 0.6 && avg_logprob < -0.5) || compression > 2.4 || avg_logprob < -1.0;
    if is_hallucination {
        log::warn!(
            "[whisper] 丢弃疑似幻听段落: no_speech={:.2} avg_logprob={:.2} compression={:.2} text={:?}",
            no_speech,
            avg_logprob,
            compression,
            text.trim()
        );
        continue;
    }
    kept.push_str(text);
}

let kept = kept.trim().to_string();

@H-Chris233 H-Chris233 self-assigned this Aug 4, 2026
@H-Chris233
H-Chris233 merged commit 1fc567c into Open-Less:main Aug 4, 2026
5 checks passed
appergb added a commit that referenced this pull request Aug 5, 2026
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