voirs 0.1.0-alpha.2

Advanced voice synthesis and speech processing library for Rust
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
# Troubleshooting

This guide helps you diagnose and resolve common issues with VoiRS Recognizer.

## Common Issues

### Installation Problems

#### "could not find system library 'alsa'" (Linux)

**Problem**: Missing ALSA development libraries on Linux.

**Solution**:
```bash
# Ubuntu/Debian
sudo apt update
sudo apt install libasound2-dev pkg-config

# CentOS/RHEL/Fedora
sudo yum install alsa-lib-devel pkgconfig
# or
sudo dnf install alsa-lib-devel pkgconfig
```

#### "linking with 'cc' failed" (macOS)

**Problem**: Missing Xcode command line tools.

**Solution**:
```bash
xcode-select --install
```

#### "failed to run custom build command for 'some-sys'"

**Problem**: Missing C compiler or build tools.

**Solution**:
```bash
# Install build essentials
# Ubuntu/Debian
sudo apt install build-essential

# macOS
xcode-select --install

# Windows
# Install Visual Studio Build Tools
```

### Runtime Errors

#### `RecognitionError::ModelLoadError`

**Problem**: Failed to load recognition model.

**Possible Causes**:
- Insufficient memory
- Corrupted model files
- Incompatible model format

**Solutions**:
```rust
// Try a smaller model size
let config = RecognitionConfig::default()
    .with_model_size(ModelSize::Tiny);

// Check available memory
println!("Available memory: {} GB", 
         sys_info::mem_info().unwrap().avail / 1024 / 1024);

// Clear model cache
let config = RecognitionConfig::default()
    .with_clear_cache(true);
```

#### `RecognitionError::AudioError`

**Problem**: Audio processing failed.

**Common Causes**:
- Unsupported audio format
- Corrupted audio file
- Invalid sample rate

**Solutions**:
```rust
// Check audio format
let format = voirs_recognizer::audio_formats::detect_format("audio.wav")?;
println!("Detected format: {:?}", format);

// Convert to supported format
let config = AudioLoadConfig {
    target_sample_rate: Some(16000),
    force_mono: true,
    normalize: true,
    ..Default::default()
};
```

#### `RecognitionError::InferenceError`

**Problem**: Model inference failed.

**Solutions**:
```rust
// Reduce input size
let config = RecognitionConfig::default()
    .with_max_duration_seconds(30.0);

// Try different precision
let config = RecognitionConfig::default()
    .with_precision(Precision::Float16);

// Enable fallback backends
let config = RecognitionConfig::default()
    .with_fallback_enabled(true);
```

### Performance Issues

#### High Memory Usage

**Symptoms**: System becomes unresponsive, out-of-memory errors.

**Diagnostics**:
```rust
// Monitor memory usage
let monitor = MemoryMonitor::new();
monitor.start();

// Use memory profiling
let config = RecognitionConfig::default()
    .with_memory_profiling(true);
```

**Solutions**:
```rust
// Use smaller models
let config = RecognitionConfig::default()
    .with_model_size(ModelSize::Tiny);

// Enable memory compression
let config = RecognitionConfig::default()
    .with_memory_compression(true);

// Limit batch size
let config = RecognitionConfig::default()
    .with_batch_size(1);

// Enable garbage collection
let config = RecognitionConfig::default()
    .with_gc_enabled(true);
```

#### Slow Performance (High RTF)

**Symptoms**: Processing takes longer than real-time.

**Diagnostics**:
```rust
// Measure performance
let validator = PerformanceValidator::new();
let metrics = validator.benchmark(&recognizer, &audio).await?;
println!("RTF: {:.3}", metrics.rtf);
```

**Solutions**:
```rust
// Use GPU acceleration
let config = RecognitionConfig::default()
    .with_gpu_acceleration(true);

// Optimize threading
let config = RecognitionConfig::default()
    .with_cpu_threads(num_cpus::get());

// Reduce model size
let config = RecognitionConfig::default()
    .with_model_size(ModelSize::Base);

// Enable quantization
let config = RecognitionConfig::default()
    .with_quantization(Quantization::Int8);
```

#### High Latency in Real-time Processing

**Symptoms**: Delays in streaming recognition results.

**Solutions**:
```rust
// Reduce chunk size
let config = RecognitionConfig::default()
    .with_chunk_duration_ms(50);

// Disable heavy analysis
let config = AudioAnalysisConfig {
    prosody_analysis: false,
    speaker_analysis: false,
    ..Default::default()
};

// Use low-latency mode
let config = RecognitionConfig::default()
    .with_streaming_mode(StreamingMode::LowLatency);
```

### Audio Quality Issues

#### Poor Recognition Accuracy

**Symptoms**: Low confidence scores, incorrect transcriptions.

**Diagnostics**:
```rust
// Analyze audio quality
let analyzer = AudioAnalyzer::new(AudioAnalysisConfig::default()).await?;
let analysis = analyzer.analyze(&audio).await?;

if let Some(snr) = analysis.quality_metrics.get("snr") {
    if *snr < 10.0 {
        println!("Warning: Low SNR ({:.1} dB)", snr);
    }
}
```

**Solutions**:
```rust
// Enable preprocessing
let config = RecognitionConfig::default()
    .with_noise_suppression(true)
    .with_auto_gain_control(true);

// Use larger models
let config = RecognitionConfig::default()
    .with_model_size(ModelSize::Large);

// Improve audio quality
let load_config = AudioLoadConfig {
    normalize: true,
    remove_dc: true,
    ..Default::default()
};
```

#### "No speech detected" in VAD

**Problem**: Voice Activity Detection not finding speech.

**Solutions**:
```rust
// Adjust VAD sensitivity
let config = RecognitionConfig::default()
    .with_vad_sensitivity(0.3); // Lower threshold

// Check energy levels
let analysis = analyzer.analyze(&audio).await?;
if let Some(energy) = analysis.quality_metrics.get("energy") {
    println!("Audio energy: {:.3}", energy);
}

// Disable VAD if problematic
let config = RecognitionConfig::default()
    .with_vad(false);
```

### Multi-language Issues

#### Wrong Language Detection

**Problem**: Auto-detection chooses incorrect language.

**Solutions**:
```rust
// Explicitly set language
let config = RecognitionConfig::default()
    .with_language(LanguageCode::EnUs);

// Use language hints
let config = RecognitionConfig::default()
    .with_language_hints(vec![
        LanguageCode::EnUs,
        LanguageCode::EsEs,
    ]);
```

#### Mixing Languages in Same Audio

**Problem**: Audio contains multiple languages.

**Solutions**:
```rust
// Enable language switching
let config = RecognitionConfig::default()
    .with_auto_language_switching(true);

// Use multilingual models
let config = RecognitionConfig::default()
    .with_multilingual_model(true);
```

### GPU Issues

#### GPU Acceleration Not Working

**Problem**: CUDA/Metal acceleration not being used.

**Diagnostics**:
```rust
// Check GPU availability
if !voirs_recognizer::gpu::is_available() {
    println!("GPU acceleration not available");
}

// List available devices
let devices = voirs_recognizer::gpu::list_devices();
for device in devices {
    println!("GPU: {}", device.name);
}
```

**Solutions**:
```bash
# Install CUDA (NVIDIA)
# Check NVIDIA drivers
nvidia-smi

# Install CUDA toolkit
sudo apt install nvidia-cuda-toolkit

# For Metal (Apple Silicon)
# Ensure you're on macOS with Apple Silicon
system_profiler SPHardwareDataType | grep "Chip"
```

#### Out of GPU Memory

**Problem**: GPU runs out of memory during processing.

**Solutions**:
```rust
// Reduce GPU memory usage
let config = RecognitionConfig::default()
    .with_gpu_memory_fraction(0.5);

// Use smaller batch sizes
let config = RecognitionConfig::default()
    .with_batch_size(1);

// Enable memory clearing
let config = RecognitionConfig::default()
    .with_clear_gpu_cache(true);
```

## Debugging Tools

### Enable Debug Logging

```rust
// Enable detailed logging
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug")).init();

// Or set environment variable
// RUST_LOG=debug cargo run
```

### Performance Profiling

```rust
// Built-in profiler
let config = RecognitionConfig::default()
    .with_profiling(true);

let recognizer = Recognizer::new(config).await?;
// ... use recognizer ...

let report = recognizer.profiler().generate_report();
println!("{}", report);
```

### Memory Profiling

```bash
# Using Valgrind (Linux)
valgrind --tool=massif ./your_app
ms_print massif.out.* > memory_profile.txt

# Using heaptrack (Linux)
heaptrack ./your_app
heaptrack_gui heaptrack.your_app.*

# Using Instruments (macOS)
# Run through Xcode Instruments
```

### Performance Monitoring

```rust
// Real-time monitoring
let monitor = PerformanceMonitor::new()
    .with_rtf_threshold(1.0)
    .with_memory_threshold(2_000_000_000);

monitor.start(&recognizer);

// Check alerts
if let Some(alert) = monitor.get_alerts().pop() {
    println!("Performance Alert: {}", alert.message);
}
```

## Configuration Validation

### Validate Your Configuration

```rust
// Check configuration validity
let config = RecognitionConfig::default()
    .with_model_size(ModelSize::Large)
    .with_gpu_acceleration(true);

if let Err(e) = config.validate() {
    println!("Configuration error: {}", e);
}
```

### Test Your Setup

```rust
// Run system tests
let test_suite = SystemTestSuite::new();
let results = test_suite.run_all().await;

for (test_name, result) in results {
    match result {
        Ok(_) => println!("✅ {}", test_name),
        Err(e) => println!("❌ {}: {}", test_name, e),
    }
}
```

## Getting Help

### Collect Diagnostic Information

```rust
// Generate diagnostic report
let diagnostics = voirs_recognizer::diagnostics::collect_system_info().await;
println!("System Diagnostics:\n{}", diagnostics);
```

### Enable Crash Reporting

```rust
// Enable crash reporting (optional)
let config = RecognitionConfig::default()
    .with_crash_reporting(true);
```

### Community Support

1. **GitHub Issues**: [Report bugs and request features]https://github.com/cool-japan/voirs/issues
2. **Discussions**: [Get help from the community]https://github.com/cool-japan/voirs/discussions
3. **Documentation**: [Check the latest docs]https://docs.rs/voirs-recognizer

### Bug Report Template

When reporting issues, please include:

```text
## Environment
- OS: [e.g., Ubuntu 22.04, macOS 13.0, Windows 11]
- Rust version: [e.g., 1.70.0]
- VoiRS Recognizer version: [e.g., 0.1.0]
- Hardware: [e.g., CPU, GPU info]

## Configuration
```rust
// Your RecognitionConfig here
```

## Steps to Reproduce
1. [First step]
2. [Second step]
3. [...]

## Expected Behavior
[What you expected to happen]

## Actual Behavior
[What actually happened]

## Error Messages
```
[Any error messages or logs]
```

## Additional Context
[Any other relevant information]
```

## Performance Baselines

### Expected Performance Ranges

| Model Size | RTF Range | Memory Usage | Accuracy |
|------------|-----------|--------------|----------|
| Tiny       | 0.05-0.15 | 100-200MB    | 85-90%   |
| Base       | 0.15-0.25 | 200-400MB    | 90-94%   |
| Small      | 0.25-0.40 | 800MB-1.2GB  | 94-96%   |
| Medium     | 0.40-0.70 | 2-3GB        | 96-97%   |
| Large      | 0.70-1.20 | 4-6GB        | 97-98%   |

### Hardware Recommendations

| Use Case | CPU | RAM | GPU |
|----------|-----|-----|-----|
| Development | 4+ cores | 8GB | Optional |
| Production | 8+ cores | 16GB | Recommended |
| Real-time | 8+ cores | 16GB | Required |
| Batch Processing | 16+ cores | 32GB | Recommended |

If your performance falls outside these ranges, refer to the performance tuning section above.