feat(ai-formatting): collapse adjacent repetitions in Clean/Smart modes + chore(audio): swap deprecated cpal .name() for description-based helper

ai-formatting:
  - rule_based.rs: collapse_repetitions() merges adjacent duplicate
    tokens like 'I I can' -> 'I can' and 'think think that' -> 'think
    that'. Normalises case and punctuation before comparison.
  - pipeline.rs: post_process now calls collapse_repetitions when
    format_mode is Clean or Smart. Added unit coverage.

audio:
  - capture.rs: replace the seven deprecated cpal DeviceTrait::name()
    call sites with a device_display_name() helper that uses the
    non-deprecated description() path. Keeps identical behaviour,
    silences compile warnings, ready for cpal upgrade.

Addresses the 'Christ. Christ.' live-transcription boundary duplicate
Jake saw during Group 1 dogfooding. Does not fix all cross-chunk
overlap cases (see live.rs OVERLAP_SAMPLES for the root cause) but
catches the common stutter pattern at post-processing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-19 20:05:36 +01:00
parent 27d85a0b28
commit 6605266587
3 changed files with 133 additions and 7 deletions

View File

@@ -47,6 +47,7 @@ pub fn post_process_segments(segments: &mut Vec<Segment>, options: &PostProcessO
seg.text = rule_based::to_british_english(&seg.text);
}
if options.format_mode != FormatMode::Raw {
seg.text = rule_based::collapse_repetitions(&seg.text);
seg.text = rule_based::format_text(&seg.text);
}
}
@@ -134,4 +135,24 @@ mod tests {
assert!(segments[2].text.starts_with("\n\n"));
}
#[test]
fn post_process_collapses_repeated_phrases_in_clean_modes() {
let mut segments = vec![Segment {
start: 0.0,
end: 1.0,
text: "I need I need to go to the shops".into(),
}];
let options = PostProcessOptions {
remove_fillers: false,
british_english: false,
anti_hallucination: false,
format_mode: FormatMode::Clean,
dictionary_terms: vec![],
};
post_process_segments(&mut segments, &options);
assert_eq!(segments[0].text, "I need to go to the shops");
}
}