Skip to content

Commit 7c94aa6

Browse files
Merge pull request #681 from ironmark72/patch-1
Fix: stop dropping transcripts below confidence threshold (#675)
2 parents 9f24062 + 8fb836a commit 7c94aa6

1 file changed

Lines changed: 27 additions & 19 deletions

File tree

  • frontend/src-tauri/src/audio/transcription

frontend/src-tauri/src/audio/transcription/worker.rs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ pub fn reset_speech_detected_flag() {
2323
info!("🔍 SPEECH_DETECTED_EMITTED reset to: {}", SPEECH_DETECTED_EMITTED.load(Ordering::SeqCst));
2424
}
2525

26+
/// Returns true if the transcript text is non-trivial and should be emitted.
27+
/// Filters empty/whitespace-only text; no confidence gating is applied.
28+
fn should_emit_transcript(text: &str) -> bool {
29+
!text.trim().is_empty()
30+
}
31+
2632
#[derive(Debug, Serialize, Deserialize, Clone)]
2733
pub struct TranscriptUpdate {
2834
pub text: String,
@@ -152,24 +158,15 @@ pub fn start_transcription_task<R: Runtime>(
152158
.await
153159
{
154160
Ok((transcript, confidence_opt, is_partial)) => {
155-
// Provider-aware confidence threshold
156-
let confidence_threshold = match &engine_clone {
157-
TranscriptionEngine::Whisper(_) | TranscriptionEngine::Provider(_) => 0.3,
158-
TranscriptionEngine::Parakeet(_) => 0.0, // Parakeet has no confidence, accept all
159-
};
160-
161161
let confidence_str = match confidence_opt {
162162
Some(c) => format!("{:.2}", c),
163163
None => "N/A".to_string(),
164164
};
165165

166-
info!("🔍 Worker {} transcription result: text='{}', confidence={}, partial={}, threshold={:.2}",
167-
worker_id, transcript, confidence_str, is_partial, confidence_threshold);
166+
info!("🔍 Worker {} transcription result: text='{}', confidence={}, partial={}",
167+
worker_id, transcript, confidence_str, is_partial);
168168

169-
// Check confidence threshold (or accept if no confidence provided)
170-
let meets_threshold = confidence_opt.map_or(true, |c| c >= confidence_threshold);
171-
172-
if !transcript.trim().is_empty() && meets_threshold {
169+
if should_emit_transcript(&transcript) {
173170
// PERFORMANCE: Only log transcription results, not every processing step
174171
info!("✅ Worker {} transcribed: {} (confidence: {}, partial: {})",
175172
worker_id, transcript, confidence_str, is_partial);
@@ -227,12 +224,6 @@ pub fn start_transcription_task<R: Runtime>(
227224
);
228225
}
229226
// PERFORMANCE: Removed verbose logging of every emission
230-
} else if !transcript.trim().is_empty() && should_log_this_chunk
231-
{
232-
// PERFORMANCE: Only log low-confidence results occasionally
233-
if let Some(c) = confidence_opt {
234-
info!("Worker {} low-confidence transcription (confidence: {:.2}), skipping", worker_id, c);
235-
}
236227
}
237228
}
238229
Err(e) => {
@@ -593,4 +584,21 @@ fn format_recording_time(seconds: f64) -> String {
593584
let secs = total_seconds % 60;
594585

595586
format!("[{:02}:{:02}]", minutes, secs)
596-
}
587+
}
588+
589+
#[cfg(test)]
590+
mod tests {
591+
use super::*;
592+
593+
#[test]
594+
fn keeps_short_acknowledgements() {
595+
assert!(should_emit_transcript("Yes"));
596+
assert!(should_emit_transcript("ok"));
597+
}
598+
599+
#[test]
600+
fn drops_empty_and_whitespace_only() {
601+
assert!(!should_emit_transcript(""));
602+
assert!(!should_emit_transcript(" "));
603+
}
604+
}

0 commit comments

Comments
 (0)