fix(frontend): keep silence out of the transcript

Cutting the live capture at a pause can hand over a piece made only of silence,
typically the end of a recording. Whisper does not return nothing on those: it
invents a line, which then ended up inside the question. A piece with no speech
in it is now dropped instead of transcribed, and so is a silent tail at the end
of the capture, so the words already transcribed are the whole question.
This commit is contained in:
BlackAngelTV committed 2026-10-06 20:26:53 +02:00
1 parent 20ee8c6699
commit 036a0d1ad7
4 files changed
+43 -6

No files matched your search

+4
View File
@@ -296,6 +296,10 @@ découpée en morceaux pendant qu'on parle :
- les morceaux entrent dans la **file du thread voix**, donc dans l'ordre, et remontent en
`TranscribedPart` ; le relâchement n'envoie plus que la queue (`Transcribed`).
Un morceau qui ne contient **aucune parole** (`audio::is_silent`) est jeté au lieu d'être
transcrit : Whisper ne répond pas « rien » sur du silence, il invente une ligne (un crédit de
sous-titres, un remerciement), et elle se retrouverait dans la question.
Le modèle se charge donc pendant la première phrase, l'inférence suit la parole, et la
question est prête presque dès l'appui final. Les morceaux sont recollés par
`join_transcript`, et le texte reconnu s'affiche au fur et à mesure : la transcription
+3 -1
View File
@@ -227,7 +227,9 @@ La voix est traitée **entièrement côté client** : rien d'audio ne transite v
chaque morceau au moteur, qui les traite dans l'ordre. Un morceau est coupé dans une
**pause** — une fenêtre de 30 ms sous un seuil de RMS — pour ne jamais trancher un mot en
deux ; à défaut de pause, une coupe est forcée au bout de 4 s, et rien n'est envoyé avant
1,2 s (en dessous, Whisper n'a pas assez de contexte et invente). Deux bénéfices : le
1,2 s (en dessous, Whisper n'a pas assez de contexte et invente). Un morceau **sans
aucune parole** (une pause en fin d'enregistrement, par exemple) n'est jamais envoyé :
Whisper n'y répond pas « rien », il y invente une ligne. Deux bénéfices : le
chargement paresseux du modèle et l'essentiel de l'inférence se font pendant la phrase, et
l'appui final n'a plus que la **queue** à traiter. Ce qui est déjà transcrit s'affiche en
direct (sous-titre en mode Compagnon, ligne en italique dans la barre de saisie), et les
+9 -5
View File
@@ -746,10 +746,10 @@ impl JarviseApp {
let remaining = std::mem::take(&mut self.listening);
let remaining_seconds = remaining.len() as f32 / sample_rate.max(1) as f32;
// A sliver left at the end carries no word: transcribing it would only
// give Whisper a chance to invent one, so the pieces already done are
// the whole question.
if remaining_seconds < MIN_TAIL_SECONDS {
// A sliver left at the end carries no word, and a long silence carries
// none either: transcribing either would only give Whisper a chance to
// invent one, so the pieces already done are the whole question.
if remaining_seconds < MIN_TAIL_SECONDS || audio::is_silent(&remaining) {
self.finish_transcript(String::new());
return;
}
@@ -774,7 +774,11 @@ impl JarviseApp {
return;
};
let piece: Vec<f32> = self.listening.drain(..cut).collect();
self.voice.transcribe_part(piece, sample_rate);
// A piece cut at a pause may hold nothing but silence, and Whisper
// invents a line on those rather than returning nothing.
if !audio::is_silent(&piece) {
self.voice.transcribe_part(piece, sample_rate);
}
}
/// Ends the transcription: joins what the pieces already said with the last
+27
View File
@@ -131,6 +131,16 @@ pub fn rms(samples: &[f32]) -> f32 {
(sum / samples.len() as f32).sqrt()
}
/// Whether a whole piece carries no speech at all.
///
/// Cutting at a pause can hand over a piece made only of silence — the end of a
/// recording, or a silence that started right after a cut. Whisper does not
/// answer nothing on those: it invents a line (a subtitle credit, a thanks),
/// which would then land in the user's question.
pub fn is_silent(samples: &[f32]) -> bool {
rms(samples) < SILENCE_RMS
}
/// End of the last pause in `samples`, if the buffer holds one.
///
/// Cutting in a pause is what keeps a word whole: a cut in the middle of \"bonjour\"
@@ -441,6 +451,23 @@ mod tests {
assert_eq!(chunk_cut(&samples, RATE), None);
}
#[test]
fn a_piece_of_pure_silence_is_recognised() {
assert!(super::is_silent(&vec![0.0_f32; RATE as usize]));
// Microphone noise floor, well under any spoken level.
assert!(super::is_silent(&vec![0.0008_f32; RATE as usize]));
}
#[test]
fn a_piece_with_speech_in_it_is_not_silent() {
assert!(!super::is_silent(&vec![0.3_f32; RATE as usize / 10]));
// One short word followed by a long room silence must still be sent.
let mut piece = vec![0.2_f32; RATE as usize / 8];
piece.extend(std::iter::repeat_n(0.0, 2 * RATE as usize));
assert!(!super::is_silent(&piece), "the word would be lost");
}
#[test]
fn silence_is_cut_at_the_shorter_threshold() {
// A gap right after the minimum: no need to wait for the hard limit.