From 7f751ce26119c8d2ef1fc4d00fb957e8a026b5f0 Mon Sep 17 00:00:00 2001 From: femshima <49227365+femshima@users.noreply.github.com> Date: Sun, 26 May 2024 07:58:32 +0900 Subject: [PATCH] fix panic when empty string is provided and speed is set --- src/duration.rs | 5 +++++ src/lib.rs | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/duration.rs b/src/duration.rs index f4dcaf5..0613dbf 100644 --- a/src/duration.rs +++ b/src/duration.rs @@ -91,6 +91,11 @@ impl DurationEstimator { let rho = (target_length as f64 - mean) / vari; let mut duration = Self::estimate_duration(duration_params, rho); + if duration.len() == 0 { + // If there is no duration that can be adjusted to match frame_length, + // simply return an empty duration + return vec![]; + } // loop estimation let mut sum: usize = duration.iter().sum(); diff --git a/src/lib.rs b/src/lib.rs index ede4536..18a86b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -136,8 +136,13 @@ mod tests { #[test] fn empty() { - let engine = Engine::load(&[MODEL_NITECH_ATR503]).unwrap(); + let mut engine = Engine::load(&[MODEL_NITECH_ATR503]).unwrap(); let labels: [&str; 0] = []; + + let speech = engine.synthesize(&labels[..]).unwrap(); + assert_eq!(speech.len(), 0); + + engine.condition.set_speed(1.2); let speech = engine.synthesize(&labels[..]).unwrap(); assert_eq!(speech.len(), 0); }