Skip to content

Commit

Permalink
fix panic when empty string is provided and speed is set
Browse files Browse the repository at this point in the history
  • Loading branch information
femshima committed May 25, 2024
1 parent 8e7e0cc commit 7f751ce
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 7f751ce

Please sign in to comment.