feat(terra): multilingual whisper small for luna's voice
base.en heard "backup" as "Mac up" and turned German into English nonsense. small with -l auto gets both right at ~1s per turn (vs ~0.4s); turbo was ~2.3s for no visible gain. Drops the subtitle credits multilingual whisper invents out of silence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011XkDJkdDzneVVdnkZfrvTY
This commit is contained in:
@@ -6,7 +6,12 @@ use tokio::process::Command;
|
||||
/// Shells out to whisper-cli rather than linking whisper.cpp: nixpkgs already
|
||||
/// ships whisper-cpp-vulkan built against this box's GPU stack, and a bundled
|
||||
/// build would have to rediscover that at cargo time.
|
||||
pub async fn transcribe(bin: &str, model: &Path, samples: &[f32]) -> Result<String> {
|
||||
pub async fn transcribe(
|
||||
bin: &str,
|
||||
model: &Path,
|
||||
language: &str,
|
||||
samples: &[f32],
|
||||
) -> Result<String> {
|
||||
// Whisper hallucinates confident words into silence — "you", "Thank
|
||||
// you.", "Bye." — which then reach luna as if spoken. Duration alone does
|
||||
// not catch it (a held key over a quiet room is long AND empty), so gate
|
||||
@@ -26,7 +31,7 @@ pub async fn transcribe(bin: &str, model: &Path, samples: &[f32]) -> Result<Stri
|
||||
.arg(&wav)
|
||||
// -nt: transcript only, no [00:00:00] prefixes. -np: no progress
|
||||
// banner. Together they make stdout exactly the text.
|
||||
.args(["-nt", "-np"])
|
||||
.args(["-nt", "-np", "-l", language])
|
||||
.output()
|
||||
.await?;
|
||||
let _ = std::fs::remove_file(&wav);
|
||||
@@ -37,7 +42,11 @@ pub async fn transcribe(bin: &str, model: &Path, samples: &[f32]) -> Result<Stri
|
||||
String::from_utf8_lossy(&out.stderr).trim()
|
||||
);
|
||||
}
|
||||
Ok(clean(&String::from_utf8_lossy(&out.stdout)))
|
||||
let text = clean(&String::from_utf8_lossy(&out.stdout));
|
||||
if subtitle_credit(&text) {
|
||||
return Ok(String::new());
|
||||
}
|
||||
Ok(text)
|
||||
}
|
||||
|
||||
/// Scales a quiet recording up before whisper sees it.
|
||||
@@ -79,6 +88,14 @@ fn has_speech(samples: &[f32]) -> bool {
|
||||
})
|
||||
}
|
||||
|
||||
/// Multilingual whisper fills silence with the subtitle credits it was trained
|
||||
/// on ("Untertitel im Auftrag des ZDF, 2017", "Untertitel der Amara.org-Community").
|
||||
/// Nobody says these to luna, so the whole transcript is dropped.
|
||||
fn subtitle_credit(text: &str) -> bool {
|
||||
let t = text.to_lowercase();
|
||||
t.contains("untertitel") || t.contains("amara.org")
|
||||
}
|
||||
|
||||
/// whisper emits bracketed non-speech annotations ([BLANK_AUDIO], (wind
|
||||
/// blowing)) that are not words and must not reach the agent.
|
||||
fn clean(raw: &str) -> String {
|
||||
@@ -97,7 +114,7 @@ fn clean(raw: &str) -> String {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{clean, has_speech, normalize};
|
||||
use super::{clean, has_speech, normalize, subtitle_credit};
|
||||
use crate::audio::STT_RATE;
|
||||
|
||||
fn peak(v: &[f32]) -> f32 {
|
||||
@@ -165,6 +182,13 @@ mod tests {
|
||||
assert_eq!(clean("[ music ] real words"), "real words");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drops_subtitle_credits() {
|
||||
assert!(subtitle_credit("Untertitel im Auftrag des ZDF, 2017"));
|
||||
assert!(subtitle_credit("Untertitel der Amara.org-Community"));
|
||||
assert!(!subtitle_credit("Ist das Backup auf jupiter gelaufen?"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collapses_whitespace() {
|
||||
assert_eq!(clean(" a b \n c "), "a b c");
|
||||
|
||||
Reference in New Issue
Block a user