Skip to content

Commit

Permalink
fix example (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
femshima authored Mar 1, 2024
1 parent 13d1e72 commit 20d89cd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
24 changes: 13 additions & 11 deletions examples/genji/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use jbonsai::engine::Engine;
use jbonsai::{engine::Engine, model::interporation_weight::Weights};

fn main() -> Result<(), Box<dyn std::error::Error>> {
let label_str = std::fs::read_to_string("examples/genji/genji.lab")?;
Expand All @@ -7,17 +7,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
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(
Expand All @@ -29,9 +31,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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(())
Expand Down
15 changes: 8 additions & 7 deletions examples/is-bonsai/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
"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(
Expand All @@ -43,9 +44,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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(())
Expand Down

0 comments on commit 20d89cd

Please sign in to comment.