piper-plus 0.2.0

High-quality neural text-to-speech engine with 8-language support
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
use piper_plus::PiperError;

// --- 1. ConfigNotFound ---
#[test]
fn test_config_not_found() {
    let err = PiperError::ConfigNotFound {
        path: "/foo/bar".to_string(),
    };
    let msg = format!("{}", err);
    assert!(msg.contains("/foo/bar"), "Display should contain path");
    assert!(msg.contains("config"), "Display should mention config");
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty(), "Debug should produce output");
    match err {
        PiperError::ConfigNotFound { path } => assert_eq!(path, "/foo/bar"),
        _ => panic!("wrong variant"),
    }
}

// --- 2. InvalidConfig ---
#[test]
fn test_invalid_config() {
    let err = PiperError::InvalidConfig {
        reason: "missing field".to_string(),
    };
    let msg = format!("{}", err);
    assert!(
        msg.contains("missing field"),
        "Display should contain reason"
    );
    assert!(
        msg.contains("invalid config"),
        "Display should mention invalid config"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::InvalidConfig { reason } => assert_eq!(reason, "missing field"),
        _ => panic!("wrong variant"),
    }
}

// --- 3. ModelLoad ---
#[test]
fn test_model_load() {
    let err = PiperError::ModelLoad("onnx init failed".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("onnx init failed"),
        "Display should contain inner message"
    );
    assert!(
        msg.contains("model load"),
        "Display should mention model load"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::ModelLoad(s) => assert_eq!(s, "onnx init failed"),
        _ => panic!("wrong variant"),
    }
}

// --- 4. UnsupportedLanguage ---
#[test]
fn test_unsupported_language() {
    let err = PiperError::UnsupportedLanguage {
        code: "xx".to_string(),
    };
    let msg = format!("{}", err);
    assert!(msg.contains("xx"), "Display should contain language code");
    assert!(
        msg.contains("unsupported language"),
        "Display should mention unsupported language"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::UnsupportedLanguage { code } => assert_eq!(code, "xx"),
        _ => panic!("wrong variant"),
    }
}

// --- 5. UnknownPhoneme ---
#[test]
fn test_unknown_phoneme() {
    let err = PiperError::UnknownPhoneme {
        phoneme: "zz".to_string(),
    };
    let msg = format!("{}", err);
    assert!(msg.contains("zz"), "Display should contain phoneme");
    assert!(
        msg.contains("unknown phoneme"),
        "Display should mention unknown phoneme"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::UnknownPhoneme { phoneme } => assert_eq!(phoneme, "zz"),
        _ => panic!("wrong variant"),
    }
}

// --- 6. Inference ---
#[test]
fn test_inference() {
    let err = PiperError::Inference("session run failed".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("session run failed"),
        "Display should contain inner message"
    );
    assert!(
        msg.contains("inference failed"),
        "Display should mention inference"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::Inference(s) => assert_eq!(s, "session run failed"),
        _ => panic!("wrong variant"),
    }
}

// --- 7. AudioOutput ---
#[test]
fn test_audio_output() {
    let io_err = std::io::Error::new(std::io::ErrorKind::NotFound, "file missing");
    let err = PiperError::AudioOutput(io_err);
    let msg = format!("{}", err);
    assert!(
        msg.contains("file missing"),
        "Display should contain io error message"
    );
    assert!(
        msg.contains("audio output"),
        "Display should mention audio output"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match &err {
        PiperError::AudioOutput(e) => assert_eq!(e.kind(), std::io::ErrorKind::NotFound),
        _ => panic!("wrong variant"),
    }
}

// --- 8. JsonParse ---
#[test]
fn test_json_parse() {
    let json_err = serde_json::from_str::<serde_json::Value>("not json").unwrap_err();
    let expected_msg = json_err.to_string();
    let err = PiperError::JsonParse(json_err);
    let msg = format!("{}", err);
    assert!(
        msg.contains(&expected_msg),
        "Display should contain serde_json error message"
    );
    assert!(
        msg.contains("JSON parse"),
        "Display should mention JSON parse"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match &err {
        PiperError::JsonParse(_) => {}
        _ => panic!("wrong variant"),
    }
}

// --- 9. WavWrite ---
#[test]
fn test_wav_write() {
    let err = PiperError::WavWrite("header corrupt".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("header corrupt"),
        "Display should contain inner message"
    );
    assert!(
        msg.contains("WAV write"),
        "Display should mention WAV write"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::WavWrite(s) => assert_eq!(s, "header corrupt"),
        _ => panic!("wrong variant"),
    }
}

// --- 10. Phonemize ---
#[test]
fn test_phonemize() {
    let err = PiperError::Phonemize("g2p failed".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("g2p failed"),
        "Display should contain inner message"
    );
    assert!(
        msg.contains("phonemization"),
        "Display should mention phonemization"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::Phonemize(s) => assert_eq!(s, "g2p failed"),
        _ => panic!("wrong variant"),
    }
}

// --- 11. DictionaryLoad ---
#[test]
fn test_dictionary_load() {
    let err = PiperError::DictionaryLoad {
        path: "/dict/custom.txt".to_string(),
    };
    let msg = format!("{}", err);
    assert!(
        msg.contains("/dict/custom.txt"),
        "Display should contain path"
    );
    assert!(
        msg.contains("dictionary load"),
        "Display should mention dictionary load"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::DictionaryLoad { path } => assert_eq!(path, "/dict/custom.txt"),
        _ => panic!("wrong variant"),
    }
}

// --- 12. JPreprocessInit ---
#[test]
fn test_jpreprocess_init() {
    let err = PiperError::JPreprocessInit("dict not found".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("dict not found"),
        "Display should contain inner message"
    );
    assert!(
        msg.contains("jpreprocess"),
        "Display should mention jpreprocess"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::JPreprocessInit(s) => assert_eq!(s, "dict not found"),
        _ => panic!("wrong variant"),
    }
}

// --- 13. LabelParse ---
#[test]
fn test_label_parse() {
    let err = PiperError::LabelParse("bad format".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("bad format"),
        "Display should contain inner message"
    );
    assert!(
        msg.contains("label parse"),
        "Display should mention label parse"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::LabelParse(s) => assert_eq!(s, "bad format"),
        _ => panic!("wrong variant"),
    }
}

// --- 14. PhonemeIdNotFound ---
#[test]
fn test_phoneme_id_not_found() {
    let err = PiperError::PhonemeIdNotFound {
        phoneme: "ky".to_string(),
    };
    let msg = format!("{}", err);
    assert!(msg.contains("ky"), "Display should contain phoneme");
    assert!(
        msg.contains("phoneme ID not found"),
        "Display should mention phoneme ID not found"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::PhonemeIdNotFound { phoneme } => assert_eq!(phoneme, "ky"),
        _ => panic!("wrong variant"),
    }
}

// --- 15. Streaming ---
#[test]
fn test_streaming() {
    let err = PiperError::Streaming("channel closed".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("channel closed"),
        "Display should contain inner message"
    );
    assert!(
        msg.contains("streaming"),
        "Display should mention streaming"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::Streaming(s) => assert_eq!(s, "channel closed"),
        _ => panic!("wrong variant"),
    }
}

// --- 16. Playback ---
#[test]
fn test_playback() {
    let err = PiperError::Playback("no audio device".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("no audio device"),
        "Display should contain inner message"
    );
    assert!(msg.contains("playback"), "Display should mention playback");
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::Playback(s) => assert_eq!(s, "no audio device"),
        _ => panic!("wrong variant"),
    }
}

// --- 17. Timing ---
#[test]
fn test_timing() {
    let err = PiperError::Timing("alignment mismatch".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("alignment mismatch"),
        "Display should contain inner message"
    );
    assert!(msg.contains("timing"), "Display should mention timing");
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::Timing(s) => assert_eq!(s, "alignment mismatch"),
        _ => panic!("wrong variant"),
    }
}

// --- 18. Download ---
#[test]
fn test_download() {
    let err = PiperError::Download("404 not found".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("404 not found"),
        "Display should contain inner message"
    );
    assert!(msg.contains("download"), "Display should mention download");
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::Download(s) => assert_eq!(s, "404 not found"),
        _ => panic!("wrong variant"),
    }
}

// --- 19. Resample ---
#[test]
fn test_resample() {
    let err = PiperError::Resample("unsupported rate".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("unsupported rate"),
        "Display should contain inner message"
    );
    assert!(
        msg.contains("resampling"),
        "Display should mention resampling"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::Resample(s) => assert_eq!(s, "unsupported rate"),
        _ => panic!("wrong variant"),
    }
}

// --- 20. Device ---
#[test]
fn test_device() {
    let err = PiperError::Device("GPU unavailable".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("GPU unavailable"),
        "Display should contain inner message"
    );
    assert!(msg.contains("device"), "Display should mention device");
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::Device(s) => assert_eq!(s, "GPU unavailable"),
        _ => panic!("wrong variant"),
    }
}

// --- 21. Batch ---
#[test]
fn test_batch() {
    let err = PiperError::Batch("empty input".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("empty input"),
        "Display should contain inner message"
    );
    assert!(
        msg.contains("batch processing"),
        "Display should mention batch processing"
    );
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::Batch(s) => assert_eq!(s, "empty input"),
        _ => panic!("wrong variant"),
    }
}

// --- 22. Wasm ---
#[test]
fn test_wasm() {
    let err = PiperError::Wasm("wasm memory limit".to_string());
    let msg = format!("{}", err);
    assert!(
        msg.contains("wasm memory limit"),
        "Display should contain inner message"
    );
    assert!(msg.contains("WASM"), "Display should mention WASM");
    let dbg = format!("{:?}", err);
    assert!(!dbg.is_empty());
    match err {
        PiperError::Wasm(s) => assert_eq!(s, "wasm memory limit"),
        _ => panic!("wrong variant"),
    }
}

// --- 23. From<std::io::Error> -> AudioOutput ---
#[test]
fn test_from_io_error() {
    let io_err = std::io::Error::new(std::io::ErrorKind::PermissionDenied, "access denied");
    let err: PiperError = PiperError::from(io_err);
    match &err {
        PiperError::AudioOutput(e) => {
            assert_eq!(e.kind(), std::io::ErrorKind::PermissionDenied);
            assert!(e.to_string().contains("access denied"));
        }
        _ => panic!("From<io::Error> should produce AudioOutput, got: {:?}", err),
    }
}

// --- 24. From<serde_json::Error> -> JsonParse ---
#[test]
fn test_from_serde_json_error() {
    let json_err = serde_json::from_str::<serde_json::Value>("{invalid").unwrap_err();
    let expected_msg = json_err.to_string();
    let err: PiperError = PiperError::from(json_err);
    match &err {
        PiperError::JsonParse(e) => {
            assert_eq!(e.to_string(), expected_msg);
        }
        _ => panic!(
            "From<serde_json::Error> should produce JsonParse, got: {:?}",
            err
        ),
    }
}