use voirs_sdk::prelude::*;
#[tokio::main]
async fn main() -> Result<(), VoirsError> {
voirs_sdk::logging::init_logging("info")?;
println!("Creating VoiRS pipeline...");
let pipeline = VoirsPipelineBuilder::new()
.build()
.await?;
println!("Pipeline created successfully!");
let text = "Hello, world! This is my first speech synthesis with VoiRS.";
println!("Synthesizing: '{}'", text);
let audio = pipeline.synthesize(text)?;
println!("Synthesis complete! Generated {} samples at {} Hz",
audio.len(), audio.sample_rate());
let output_path = "simple_synthesis_output.wav";
audio.save_wav(output_path)?;
println!("Audio saved to: {}", output_path);
println!("Audio duration: {:.2} seconds", audio.duration());
println!("Audio format: {} channels, {:.1} kHz",
audio.channels(), audio.sample_rate() / 1000.0);
#[cfg(feature = "audio_playback")]
{
println!("Playing audio...");
audio.play()?;
}
Ok(())
}
#[tokio::main]
async fn minimal_example() -> Result<(), VoirsError> {
let pipeline = VoirsPipelineBuilder::new().build().await?;
let audio = pipeline.synthesize("Hello, world!")?;
audio.save_wav("minimal_output.wav")?;
Ok(())
}
#[tokio::main]
async fn example_with_error_handling() {
match VoirsPipelineBuilder::new().build().await {
Ok(pipeline) => {
match pipeline.synthesize("Hello, world!") {
Ok(audio) => {
println!("Successfully synthesized {} samples", audio.len());
if let Err(e) = audio.save_wav("error_handling_output.wav") {
eprintln!("Failed to save audio: {}", e);
} else {
println!("Audio saved successfully!");
}
}
Err(e) => {
eprintln!("Synthesis failed: {}", e);
eprintln!("Error details: {:?}", e);
}
}
}
Err(e) => {
eprintln!("Failed to create pipeline: {}", e);
eprintln!("Possible causes:");
eprintln!(" - Missing model files");
eprintln!(" - Insufficient system resources");
eprintln!(" - Invalid configuration");
}
}
}