/* git submodule update --init wget https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_US/hfc_female/medium/en_US-hfc_female-medium.onnx wget https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_US/hfc_female/medium/en_US-hfc_female-medium.onnx.json cargo run --example usage en_US-hfc_female-medium.onnx.json */ use piper_rs::synth::SonataSpeechSynthesizer; use rodio::buffer::SamplesBuffer; use std::path::Path; fn init_ort_environment() { ort::init() .with_name("piper-rs") .commit() .expect("Failed to initialize onnxruntime"); } fn main() { init_ort_environment(); let config_path = std::env::args().nth(1).expect("Please specify config path"); let text = "Hello! i'm playing audio from memory directly.".to_string(); let voice = piper_rs::from_config_path(Path::new(&config_path)).unwrap(); let synth = SonataSpeechSynthesizer::new(voice).unwrap(); let mut samples: Vec = Vec::new(); let audio = synth.synthesize_parallel(text, None).unwrap(); for result in audio { samples.append(&mut result.unwrap().into_vec()); } let (_stream, handle) = rodio::OutputStream::try_default().unwrap(); let sink = rodio::Sink::try_new(&handle).unwrap(); let buf = SamplesBuffer::new(1, 22050, samples); sink.append(buf); sink.sleep_until_end(); }