diff --git a/examples/genji/main.rs b/examples/genji/main.rs index f18c409..b4a46b8 100644 --- a/examples/genji/main.rs +++ b/examples/genji/main.rs @@ -1,4 +1,4 @@ -use jbonsai::engine::Engine; +use jbonsai::{engine::Engine, model::interporation_weight::Weights}; fn main() -> Result<(), Box> { let label_str = std::fs::read_to_string("examples/genji/genji.lab")?; @@ -7,17 +7,19 @@ fn main() -> Result<(), Box> { let mut engine = Engine::load(&vec![ "models/tohoku-f01/tohoku-f01-sad.htsvoice", "models/tohoku-f01/tohoku-f01-happy.htsvoice", - ]); + ])?; let iw = engine.condition.get_interporation_weight_mut(); - iw.set_duration(vec![0.5, 0.5]); - iw.set_parameter(0, vec![0.5, 0.5]); - iw.set_parameter(1, vec![0.5, 0.5]); - iw.set_parameter(2, vec![1.0, 0.0]); - engine.synthesize_from_strings(&lines); + iw.set_duration(Weights::new(&[0.5, 0.5])?)?; + iw.set_parameter(0, Weights::new(&[0.5, 0.5])?)?; + iw.set_parameter(1, Weights::new(&[0.5, 0.5])?)?; + iw.set_parameter(2, Weights::new(&[1.0, 0.0])?)?; + + let gstream = engine.synthesize_from_strings(&lines); + let speech = gstream.get_speech(); println!( "The synthesized voice has {} samples in total.", - engine.get_total_nsamples() + speech.len() ); // let mut writer = hound::WavWriter::create( @@ -29,9 +31,9 @@ fn main() -> Result<(), Box> { // sample_format: hound::SampleFormat::Int, // }, // )?; - // for i in 0..engine.get_total_nsamples() { - // let value = engine.get_generated_speech_with_index(i); - // writer.write_sample(value as i16)?; + // for &value in speech { + // let clamped = value.min(i16::MAX as f64).max(i16::MIN as f64); + // writer.write_sample(clamped as i16)?; // } Ok(()) diff --git a/examples/is-bonsai/main.rs b/examples/is-bonsai/main.rs index 31ce6f4..41c273e 100644 --- a/examples/is-bonsai/main.rs +++ b/examples/is-bonsai/main.rs @@ -24,14 +24,15 @@ fn main() -> Result<(), Box> { "k^a-sil+xx=xx/A:xx+xx+xx/B:xx-xx_xx/C:xx_xx+xx/D:xx+xx_xx/E:7_5!1_xx-xx/F:xx_xx#xx_xx@xx_xx|xx_xx/G:xx_xx%xx_xx_xx/H:2_10/I:xx-xx@xx+xx&xx-xx|xx+xx/J:xx_xx/K:1+2-10", ].iter().map(|l| l.to_string()).collect(); - let mut engine = Engine::load(&vec![ + let engine = Engine::load(&vec![ "models/hts_voice_nitech_jp_atr503_m001-1.05/nitech_jp_atr503_m001.htsvoice".to_string(), - ]); - engine.synthesize_from_strings(&lines); + ])?; + let gstream = engine.synthesize_from_strings(&lines); + let speech = gstream.get_speech(); println!( "The synthesized voice has {} samples in total.", - engine.get_total_nsamples() + speech.len() ); // let mut writer = hound::WavWriter::create( @@ -43,9 +44,9 @@ fn main() -> Result<(), Box> { // sample_format: hound::SampleFormat::Int, // }, // )?; - // for i in 0..engine.get_total_nsamples() { - // let value = engine.get_generated_speech_with_index(i); - // writer.write_sample(value as i16)?; + // for &value in speech { + // let clamped = value.min(i16::MAX as f64).max(i16::MIN as f64); + // writer.write_sample(clamped as i16)?; // } Ok(())