voirs-sdk 0.1.0-rc.1

Unified SDK and public API for VoiRS speech synthesis
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
# voirs-sdk

[![Crates.io](https://img.shields.io/crates/v/voirs.svg)](https://crates.io/crates/voirs)
[![Documentation](https://docs.rs/voirs/badge.svg)](https://docs.rs/voirs)

**Unified SDK and public API for VoiRS speech synthesis framework.**

The VoiRS SDK provides a comprehensive, easy-to-use interface for integrating high-quality text-to-speech synthesis into your Rust applications. It unifies all VoiRS components under a single, well-designed API with powerful builder patterns, async support, and extensive customization options.

## Features

- **🎯 Unified API**: Single entry point for all VoiRS functionality
- **🔧 Builder Pattern**: Fluent, discoverable API for configuration
- **⚡ Async/Await**: Non-blocking operations with full async support
- **🎭 Voice Control**: Easy voice management and customization
- **📱 Streaming**: Real-time synthesis with low latency
- **🔌 Extensible**: Plugin system for custom components
- **💾 Caching**: Intelligent model and result caching
- **🛡️ Error Handling**: Comprehensive error types with context

## Quick Start

Add VoiRS to your `Cargo.toml`:

```toml
[dependencies]
voirs = "0.1"

# Or with specific features
voirs = { version = "0.1", features = ["gpu", "streaming", "ssml"] }
```

### Basic Usage

```rust
use voirs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), VoirsError> {
    // Create a simple pipeline
    let pipeline = VoirsPipeline::builder()
        .build()
        .await?;
    
    // Synthesize text to audio
    let audio = pipeline
        .synthesize("Hello, world! Welcome to VoiRS.")
        .await?;
    
    // Save to file
    audio.save_wav("hello.wav")?;
    
    println!("Synthesis complete! Duration: {:.2}s", audio.duration());
    Ok(())
}
```

### Advanced Configuration

```rust
use voirs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), VoirsError> {
    let pipeline = VoirsPipeline::builder()
        .with_voice("en-US-female-calm")
        .with_quality(Quality::Ultra)
        .with_gpu_acceleration(true)
        .with_streaming(StreamConfig {
            chunk_size: 256,
            overlap: 64,
            max_latency_ms: 50,
        })
        .with_enhancement(Enhancement {
            noise_reduction: true,
            dynamic_range_compression: true,
            high_frequency_boost: 0.1,
        })
        .build()
        .await?;
    
    let audio = pipeline
        .synthesize("This is high-quality synthesis with GPU acceleration.")
        .await?;
    
    audio.save("output.flac", AudioFormat::Flac)?;
    Ok(())
}
```

## Core API

### VoirsPipeline

The main entry point for speech synthesis.

```rust
impl VoirsPipeline {
    /// Create a new pipeline builder
    pub fn builder() -> VoirsPipelineBuilder;
    
    /// Synthesize text to audio
    pub async fn synthesize(&self, text: &str) -> Result<AudioBuffer>;
    
    /// Synthesize with custom configuration
    pub async fn synthesize_with_config(
        &self, 
        text: &str, 
        config: &SynthesisConfig
    ) -> Result<AudioBuffer>;
    
    /// Synthesize SSML markup
    pub async fn synthesize_ssml(&self, ssml: &str) -> Result<AudioBuffer>;
    
    /// Stream synthesis for long texts
    pub async fn synthesize_stream(
        &self,
        text: &str
    ) -> Result<impl Stream<Item = Result<AudioBuffer>>>;
    
    /// Change voice during runtime
    pub async fn set_voice(&mut self, voice: &str) -> Result<()>;
    
    /// Get current voice information
    pub fn current_voice(&self) -> &VoiceInfo;
    
    /// List available voices
    pub async fn list_voices(&self) -> Result<Vec<VoiceInfo>>;
}
```

### VoirsPipelineBuilder

Fluent builder for configuring the synthesis pipeline.

```rust
impl VoirsPipelineBuilder {
    /// Set the voice to use
    pub fn with_voice(self, voice: impl Into<String>) -> Self;
    
    /// Set synthesis quality
    pub fn with_quality(self, quality: Quality) -> Self;
    
    /// Enable GPU acceleration
    pub fn with_gpu_acceleration(self, enabled: bool) -> Self;
    
    /// Configure streaming synthesis
    pub fn with_streaming(self, config: StreamConfig) -> Self;
    
    /// Enable audio enhancement
    pub fn with_enhancement(self, enhancement: Enhancement) -> Self;
    
    /// Set device for computation
    pub fn with_device(self, device: Device) -> Self;
    
    /// Set custom cache directory
    pub fn with_cache_dir(self, path: impl AsRef<Path>) -> Self;
    
    /// Add custom plugin
    pub fn with_plugin<P: Plugin>(self, plugin: P) -> Self;
    
    /// Build the pipeline
    pub async fn build(self) -> Result<VoirsPipeline>;
}
```

### AudioBuffer

Represents synthesized audio with rich metadata and processing capabilities.

```rust
impl AudioBuffer {
    /// Get audio samples as slice
    pub fn samples(&self) -> &[f32];
    
    /// Get sample rate in Hz
    pub fn sample_rate(&self) -> u32;
    
    /// Get number of channels
    pub fn channels(&self) -> u32;
    
    /// Get duration in seconds
    pub fn duration(&self) -> f32;
    
    /// Convert to different sample rate
    pub fn resample(&self, target_rate: u32) -> Result<AudioBuffer>;
    
    /// Apply audio effects
    pub fn with_effects(&self, effects: &[AudioEffect]) -> Result<AudioBuffer>;
    
    /// Save as WAV file
    pub fn save_wav(&self, path: impl AsRef<Path>) -> Result<()>;
    
    /// Save in specified format
    pub fn save(&self, path: impl AsRef<Path>, format: AudioFormat) -> Result<()>;
    
    /// Play audio through system speakers
    pub fn play(&self) -> Result<()>;
    
    /// Get audio metadata
    pub fn metadata(&self) -> &AudioMetadata;
}
```

## Configuration Types

### Quality Levels

```rust
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Quality {
    /// Fast synthesis with acceptable quality
    Low,
    /// Balanced speed and quality (default)
    Medium,
    /// High quality synthesis
    High,
    /// Maximum quality (slowest)
    Ultra,
}
```

### Device Selection

```rust
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Device {
    /// Automatically select best device
    Auto,
    /// Use CPU only
    Cpu,
    /// Use specific GPU
    Gpu(u32),
    /// Use Metal (macOS)
    Metal,
}
```

### Streaming Configuration

```rust
#[derive(Debug, Clone)]
pub struct StreamConfig {
    /// Size of each audio chunk in frames
    pub chunk_size: usize,
    /// Overlap between chunks for smooth concatenation
    pub overlap: usize,
    /// Maximum acceptable latency in milliseconds
    pub max_latency_ms: u32,
    /// Buffer size for audio output
    pub buffer_size: usize,
}
```

### Audio Enhancement

```rust
#[derive(Debug, Clone)]
pub struct Enhancement {
    /// Enable noise reduction
    pub noise_reduction: bool,
    /// Enable dynamic range compression
    pub dynamic_range_compression: bool,
    /// High frequency boost (0.0 - 1.0)
    pub high_frequency_boost: f32,
    /// Warmth enhancement for natural sound
    pub warmth: f32,
    /// Stereo widening effect
    pub stereo_width: f32,
}
```

## Advanced Usage Examples

### Voice Management

```rust
use voirs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), VoirsError> {
    let mut pipeline = VoirsPipeline::builder()
        .with_voice("en-US-female-calm")
        .build()
        .await?;
    
    // List available voices
    let voices = pipeline.list_voices().await?;
    for voice in voices {
        println!("Voice: {} ({})", voice.name, voice.language);
        println!("  Quality: {:?}", voice.quality);
        println!("  Features: {:?}", voice.features);
    }
    
    // Switch voice dynamically
    pipeline.set_voice("en-GB-male-formal").await?;
    
    let audio = pipeline
        .synthesize("Hello from Britain!")
        .await?;
    
    audio.save_wav("british.wav")?;
    Ok(())
}
```

### Streaming Synthesis

```rust
use voirs::prelude::*;
use futures::StreamExt;

#[tokio::main]
async fn main() -> Result<(), VoirsError> {
    let pipeline = VoirsPipeline::builder()
        .with_streaming(StreamConfig {
            chunk_size: 256,
            overlap: 64,
            max_latency_ms: 50,
            buffer_size: 1024,
        })
        .build()
        .await?;
    
    let long_text = "This is a very long text that will be synthesized in real-time chunks...";
    
    let mut stream = pipeline.synthesize_stream(long_text).await?;
    let mut chunk_count = 0;
    
    while let Some(audio_chunk) = stream.next().await {
        let chunk = audio_chunk?;
        chunk_count += 1;
        
        println!("Chunk {}: {:.3}s", chunk_count, chunk.duration());
        
        // Play each chunk immediately for real-time audio
        chunk.play()?;
    }
    
    println!("Streaming complete! {} chunks processed", chunk_count);
    Ok(())
}
```

### SSML Processing

```rust
use voirs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), VoirsError> {
    let pipeline = VoirsPipeline::builder()
        .with_voice("en-US-female-calm")
        .with_quality(Quality::High)
        .build()
        .await?;
    
    let ssml = r#"
        <speak>
            <p>Welcome to <emphasis level="strong">VoiRS</emphasis>!</p>
            
            <break time="1s"/>
            
            <p>This framework supports:</p>
            <ul>
                <li><prosody rate="slow">Slow speech</prosody></li>
                <li><prosody rate="fast">Fast speech</prosody></li>
                <li><prosody pitch="high">High pitch</prosody></li>
                <li><prosody pitch="low">Low pitch</prosody></li>
            </ul>
            
            <p>You can even specify pronunciations:
            <phoneme alphabet="ipa" ph="təˈmeɪtoʊ">tomato</phoneme>
            or <phoneme alphabet="ipa" ph="təˈmɑːtoʊ">tomato</phoneme>.</p>
        </speak>
    "#;
    
    let audio = pipeline.synthesize_ssml(ssml).await?;
    audio.save_wav("ssml_demo.wav")?;
    
    Ok(())
}
```

### Batch Processing

```rust
use voirs::prelude::*;
use futures::future::join_all;

#[tokio::main]
async fn main() -> Result<(), VoirsError> {
    let pipeline = VoirsPipeline::builder()
        .with_voice("en-US-female-calm")
        .with_quality(Quality::High)
        .build()
        .await?;
    
    let texts = vec![
        "This is the first sentence.",
        "Here's the second sentence.",
        "And finally, the third sentence.",
    ];
    
    // Process all texts concurrently
    let synthesis_tasks: Vec<_> = texts
        .iter()
        .map(|text| pipeline.synthesize(text))
        .collect();
    
    let audio_results = join_all(synthesis_tasks).await;
    
    // Save all results
    for (i, result) in audio_results.into_iter().enumerate() {
        let audio = result?;
        audio.save_wav(&format!("batch_{:02}.wav", i + 1))?;
    }
    
    println!("Batch processing complete!");
    Ok(())
}
```

### Custom Synthesis Configuration

```rust
use voirs::prelude::*;

#[tokio::main]
async fn main() -> Result<(), VoirsError> {
    let pipeline = VoirsPipeline::builder()
        .with_voice("en-US-female-calm")
        .build()
        .await?;
    
    let config = SynthesisConfig {
        speaking_rate: 1.2,          // 20% faster
        pitch_shift: 0.5,            // Half semitone higher
        volume_gain: 2.0,            // 2dB louder
        emphasis: Some(Emphasis {
            words: vec!["important".to_string(), "critical".to_string()],
            level: EmphasisLevel::Strong,
        }),
        prosody: Some(Prosody {
            rhythm: Rhythm::Natural,
            intonation: Intonation::Expressive,
        }),
        effects: vec![
            AudioEffect::Reverb {
                room_size: 0.3,
                damping: 0.5,
                wet_level: 0.1,
            },
            AudioEffect::Eq {
                low_gain: 0.0,
                mid_gain: 1.0,
                high_gain: 0.5,
            },
        ],
    };
    
    let audio = pipeline
        .synthesize_with_config(
            "This is an important and critical announcement!",
            &config
        )
        .await?;
    
    audio.save_wav("enhanced.wav")?;
    Ok(())
}
```

### Error Handling

```rust
use voirs::prelude::*;

#[tokio::main]
async fn main() {
    match create_and_synthesize().await {
        Ok(()) => println!("Synthesis completed successfully!"),
        Err(e) => handle_voirs_error(e),
    }
}

async fn create_and_synthesize() -> Result<(), VoirsError> {
    let pipeline = VoirsPipeline::builder()
        .with_voice("nonexistent-voice")  // This will cause an error
        .build()
        .await?;
    
    let audio = pipeline.synthesize("Hello").await?;
    audio.save_wav("output.wav")?;
    
    Ok(())
}

fn handle_voirs_error(error: VoirsError) {
    match error {
        VoirsError::VoiceNotFound { voice, available } => {
            eprintln!("Voice '{}' not found.", voice);
            eprintln!("Available voices:");
            for v in available {
                eprintln!("  - {}", v);
            }
        }
        VoirsError::SynthesisFailed { text, cause } => {
            eprintln!("Failed to synthesize: '{}'", text);
            eprintln!("Cause: {}", cause);
        }
        VoirsError::IoError { path, source } => {
            eprintln!("File I/O error at '{}': {}", path.display(), source);
        }
        VoirsError::DeviceError { device, message } => {
            eprintln!("Device error ({:?}): {}", device, message);
        }
        _ => {
            eprintln!("Other VoiRS error: {}", error);
        }
    }
}
```

### Plugin System

```rust
use voirs::prelude::*;

// Custom plugin for post-processing
#[derive(Debug)]
struct CustomEnhancer {
    gain: f32,
    filter_cutoff: f32,
}

impl Plugin for CustomEnhancer {
    fn name(&self) -> &str {
        "CustomEnhancer"
    }
    
    fn process(&self, audio: &mut AudioBuffer) -> Result<(), PluginError> {
        // Apply custom enhancement
        let samples = audio.samples_mut();
        for sample in samples {
            *sample *= self.gain;
            // Apply custom filtering...
        }
        Ok(())
    }
}

#[tokio::main]
async fn main() -> Result<(), VoirsError> {
    let enhancer = CustomEnhancer {
        gain: 1.2,
        filter_cutoff: 8000.0,
    };
    
    let pipeline = VoirsPipeline::builder()
        .with_voice("en-US-female-calm")
        .with_plugin(enhancer)
        .build()
        .await?;
    
    let audio = pipeline.synthesize("Hello with custom enhancement!").await?;
    audio.save_wav("enhanced.wav")?;
    
    Ok(())
}
```

## Feature Flags

The VoiRS SDK supports various feature flags for customizing functionality:

```toml
[dependencies]
voirs = { version = "0.1", features = ["full"] }

# Or select specific features:
voirs = { 
    version = "0.1", 
    features = [
        "gpu",           # GPU acceleration
        "streaming",     # Real-time streaming
        "ssml",          # SSML markup support
        "effects",       # Audio effects processing
        "ml",            # Advanced ML features
        "networking",    # Network-based features
    ] 
}
```

### Available Features

- **`gpu`**: Enable GPU acceleration (CUDA, Metal, OpenCL)
- **`streaming`**: Real-time streaming synthesis
- **`ssml`**: SSML markup processing
- **`effects`**: Audio effects and post-processing
- **`ml`**: Advanced ML features (voice cloning, etc.)
- **`networking`**: Network-based model loading and APIs
- **`python`**: Python integration (re-exports from voirs-ffi)
- **`full`**: Enable all features

## Performance

### Benchmarks

| Configuration | RTF (CPU) | RTF (GPU) | Memory | Quality (MOS) |
|---------------|-----------|-----------|--------|---------------|
| Quality::Low | 0.15× | 0.02× | 256MB | 3.8 |
| Quality::Medium | 0.28× | 0.04× | 384MB | 4.2 |
| Quality::High | 0.42× | 0.06× | 512MB | 4.4 |
| Quality::Ultra | 0.68× | 0.12× | 768MB | 4.6 |

*Benchmarks on Intel i7-12700K + RTX 4080, 22kHz synthesis*

### Performance Tips

```rust
// For maximum performance
let pipeline = VoirsPipeline::builder()
    .with_quality(Quality::Medium)    // Balance quality vs speed
    .with_gpu_acceleration(true)      // Use GPU if available
    .with_streaming(StreamConfig::fast()) // Optimize for speed
    .build()
    .await?;

// For maximum quality
let pipeline = VoirsPipeline::builder()
    .with_quality(Quality::Ultra)
    .with_enhancement(Enhancement::studio()) // High-quality enhancement
    .build()
    .await?;

// For batch processing
let pipeline = VoirsPipeline::builder()
    .with_quality(Quality::High)
    .with_cache_dir("/fast/ssd/cache")   // Use fast storage
    .build()
    .await?;

// Reuse pipeline instances to avoid initialization overhead
```

## Integration Examples

### Web Framework Integration (Axum)

```rust
use axum::{extract::Query, http::StatusCode, response::Json, routing::post, Router};
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use voirs::prelude::*;

#[derive(Deserialize)]
struct SynthesisRequest {
    text: String,
    voice: Option<String>,
    quality: Option<Quality>,
}

#[derive(Serialize)]
struct SynthesisResponse {
    audio_url: String,
    duration: f32,
    sample_rate: u32,
}

async fn synthesize_handler(
    Query(req): Query<SynthesisRequest>,
    pipeline: Arc<VoirsPipeline>,
) -> Result<Json<SynthesisResponse>, StatusCode> {
    // Configure synthesis
    let mut synthesis_config = SynthesisConfig::default();
    if let Some(quality) = req.quality {
        synthesis_config.quality = quality;
    }
    
    // Synthesize audio
    let audio = pipeline
        .synthesize_with_config(&req.text, &synthesis_config)
        .await
        .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
    
    // Save to temporary file
    let filename = format!("synthesis_{}.wav", uuid::Uuid::new_v4());
    let path = format!("/tmp/{}", filename);
    audio.save_wav(&path)
        .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;
    
    Ok(Json(SynthesisResponse {
        audio_url: format!("/audio/{}", filename),
        duration: audio.duration(),
        sample_rate: audio.sample_rate(),
    }))
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let pipeline = Arc::new(
        VoirsPipeline::builder()
            .with_voice("en-US-female-calm")
            .with_quality(Quality::High)
            .build()
            .await?
    );
    
    let app = Router::new()
        .route("/synthesize", post(synthesize_handler))
        .with_state(pipeline);
    
    println!("Server running on http://localhost:3000");
    axum::Server::bind(&"0.0.0.0:3000".parse()?)
        .serve(app.into_make_service())
        .await?;
    
    Ok(())
}
```

### Game Engine Integration

```rust
use voirs::prelude::*;
use std::sync::Arc;
use tokio::sync::Mutex;

pub struct GameNarrator {
    pipeline: Arc<VoirsPipeline>,
    current_voice: String,
}

impl GameNarrator {
    pub async fn new() -> Result<Self, VoirsError> {
        let pipeline = VoirsPipeline::builder()
            .with_voice("en-US-male-narrator")
            .with_quality(Quality::High)
            .with_streaming(StreamConfig::gaming())
            .build()
            .await?;
        
        Ok(Self {
            pipeline: Arc::new(pipeline),
            current_voice: "en-US-male-narrator".to_string(),
        })
    }
    
    pub async fn narrate(&self, text: &str) -> Result<AudioBuffer, VoirsError> {
        self.pipeline.synthesize(text).await
    }
    
    pub async fn character_speak(
        &mut self,
        character: &str,
        text: &str
    ) -> Result<AudioBuffer, VoirsError> {
        let voice = self.get_character_voice(character);
        
        if voice != self.current_voice {
            self.pipeline.set_voice(&voice).await?;
            self.current_voice = voice;
        }
        
        self.pipeline.synthesize(text).await
    }
    
    fn get_character_voice(&self, character: &str) -> String {
        match character {
            "wizard" => "en-US-male-wise",
            "princess" => "en-US-female-elegant",
            "warrior" => "en-US-male-strong",
            "narrator" => "en-US-male-narrator",
            _ => "en-US-neutral",
        }.to_string()
    }
}

// Usage in game loop
async fn game_dialogue_example() -> Result<(), VoirsError> {
    let mut narrator = GameNarrator::new().await?;
    
    // Narration
    let narration = narrator
        .narrate("The hero enters the ancient castle...")
        .await?;
    narration.play()?;
    
    // Character dialogue
    let wizard_speech = narrator
        .character_speak("wizard", "Welcome, brave adventurer!")
        .await?;
    wizard_speech.play()?;
    
    let princess_speech = narrator
        .character_speak("princess", "Please save our kingdom!")
        .await?;
    princess_speech.play()?;
    
    Ok(())
}
```

## Error Types

```rust
#[derive(Debug, thiserror::Error)]
pub enum VoirsError {
    #[error("Voice '{voice}' not found")]
    VoiceNotFound {
        voice: String,
        available: Vec<String>,
    },
    
    #[error("Synthesis failed for text: '{text}'")]
    SynthesisFailed {
        text: String,
        #[source]
        cause: Box<dyn std::error::Error + Send + Sync>,
    },
    
    #[error("Device error ({device:?}): {message}")]
    DeviceError {
        device: Device,
        message: String,
    },
    
    #[error("I/O error at path '{path}'")]
    IoError {
        path: PathBuf,
        #[source]
        source: std::io::Error,
    },
    
    #[error("Configuration error: {message}")]
    ConfigError {
        message: String,
    },
    
    #[error("Plugin error in '{plugin}': {message}")]
    PluginError {
        plugin: String,
        message: String,
    },
    
    #[error("Network error: {message}")]
    NetworkError {
        message: String,
        #[source]
        source: Option<Box<dyn std::error::Error + Send + Sync>>,
    },
}
```

## Contributing

We welcome contributions! Please see the [main repository](https://github.com/cool-japan/voirs) for contribution guidelines.

### Development Setup

```bash
git clone https://github.com/cool-japan/voirs.git
cd voirs

# Build all crates
cargo build --workspace

# Run tests
cargo test --workspace

# Run examples
cargo run --example simple_synthesis
```

## License

Licensed under the Apache License, Version 2.0 ([LICENSE](../../LICENSE)).