From 8e868894cbcaf421c263f3555af4d29bef653420 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sat, 5 Sep 2026 19:35:21 +0200 Subject: feat: piper now not a subprocess, cache system for TTS --- tests/tts_smoke.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/tts_smoke.rs (limited to 'tests') diff --git a/tests/tts_smoke.rs b/tests/tts_smoke.rs new file mode 100644 index 0000000..e98d56d --- /dev/null +++ b/tests/tts_smoke.rs @@ -0,0 +1,54 @@ +//! Smoke test: verify piper-rs loads the Polish model and synthesizes audio. + +use std::path::Path; + +#[test] +fn piper_load_and_synthesize() { + let model_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("piper"); + let onnx = model_dir.join("pl_PL-bass-high.onnx"); + let json = model_dir.join("pl_PL-bass-high.onnx.json"); + + assert!(onnx.exists(), "model file missing: {}", onnx.display()); + assert!(json.exists(), "config file missing: {}", json.display()); + + let mut piper = + piper_rs::Piper::new(&onnx, &json).expect("failed to load piper model"); + + let text = "Kamil sie zespawnił"; + let (samples, sample_rate) = piper + .create(text, false, None, None, None, None) + .expect("synthesis failed"); + + assert!(!samples.is_empty(), "no samples produced"); + assert!(sample_rate > 0, "invalid sample rate: {sample_rate}"); + assert!( + samples.len() as u32 > sample_rate / 10, + "suspiciously short output: {} samples at {} Hz", + samples.len(), + sample_rate + ); + + let duration = samples.len() as f64 / sample_rate as f64; + println!( + "OK: '{}' → {} samples @ {} Hz ({:.2}s)", + text, + samples.len(), + sample_rate, + duration, + ); + + // Second call measures cached-model synthesis speed + let start = std::time::Instant::now(); + let (samples2, sr2) = piper + .create("Kamil jest chujem", false, None, None, None, None) + .expect("second synthesis failed"); + let elapsed = start.elapsed(); + println!( + "Cached: '{}' → {} samples @ {} Hz in {:?}", + "Kamil jest chujem", + samples2.len(), + sr2, + elapsed, + ); + assert!(!samples2.is_empty()); +} -- cgit v1.2.3