Skip to main content

espeak_ng/
error.rs

1//! Error types for the espeak-ng-rs library.
2
3use crate::phoneme::PhonemeFeature;
4
5/// All errors that can be produced by the espeak-ng-rs library.
6///
7/// Variants that start with a capital letter directly correspond to
8/// `espeak_ng_STATUS` codes in `espeak_ng.h`.  Variants in `snake_case`
9/// are Rust-native additions.
10#[derive(Debug, thiserror::Error)]
11pub enum Error {
12    // ------------------------------------------------------------------
13    // Variants that map 1-to-1 onto espeak_ng_STATUS codes
14    // C: ENS_COMPILE_ERROR
15    // ------------------------------------------------------------------
16
17    /// `ENS_COMPILE_ERROR` — a compile error occurred in voice/dictionary data.
18    #[error("compile error in voice/dictionary data")]
19    CompileError,
20
21    /// `ENS_VERSION_MISMATCH` — the data file has an unexpected version tag.
22    #[error("data version mismatch: got 0x{got:06x}, expected 0x{expected:06x}")]
23    VersionMismatch {
24        /// The version tag found in the data file.
25        got: u32,
26        /// The version tag this build expects.
27        expected: u32,
28    },
29
30    /// `ENS_FIFO_BUFFER_FULL` — the audio FIFO buffer is full.
31    #[error("audio FIFO buffer is full")]
32    FifoBufferFull,
33
34    /// `ENS_NOT_INITIALIZED` — espeak-ng has not been initialised.
35    #[error("espeak-ng has not been initialised")]
36    NotInitialized,
37
38    /// `ENS_AUDIO_ERROR` — audio system error.
39    #[error("audio system error")]
40    AudioError,
41
42    /// `ENS_VOICE_NOT_FOUND` — the requested voice could not be found.
43    #[error("voice not found: {0}")]
44    VoiceNotFound(String),
45
46    /// `ENS_MBROLA_NOT_FOUND` — the MBROLA binary is not installed.
47    #[error("MBROLA binary not found")]
48    MbrolaNotFound,
49
50    /// `ENS_MBROLA_VOICE_NOT_FOUND` — the requested MBROLA voice is missing.
51    #[error("MBROLA voice not found")]
52    MbrolaVoiceNotFound,
53
54    /// `ENS_EVENT_BUFFER_FULL` — the synthesis event queue overflowed.
55    #[error("event buffer full")]
56    EventBufferFull,
57
58    /// `ENS_NOT_SUPPORTED` — the requested operation is not supported.
59    #[error("operation not supported")]
60    NotSupported,
61
62    /// `ENS_UNSUPPORTED_PHON_FORMAT` — unrecognised phoneme encoding format.
63    #[error("unsupported phoneme format")]
64    UnsupportedPhonFormat,
65
66    /// `ENS_NO_SPECT_FRAMES` — no spectral frames are available for synthesis.
67    #[error("no spectral frames available")]
68    NoSpectFrames,
69
70    /// `ENS_EMPTY_PHONEME_MANIFEST` — the phoneme manifest file is empty.
71    #[error("phoneme manifest is empty")]
72    EmptyPhonemeManifest,
73
74    /// `ENS_SPEECH_STOPPED` — synthesis was stopped mid-utterance.
75    #[error("speech was stopped")]
76    SpeechStopped,
77
78    /// `ENS_UNKNOWN_PHONEME_FEATURE` — the feature tag is not recognised.
79    #[error("unknown phoneme feature: {0}")]
80    UnknownPhonemeFeature(PhonemeFeature),
81
82    /// `ENS_UNKNOWN_TEXT_ENCODING` — the text encoding name is not recognised.
83    #[error("unknown or unsupported text encoding: {0}")]
84    UnknownTextEncoding(String),
85
86    // ------------------------------------------------------------------
87    // Rust-native errors
88    // ------------------------------------------------------------------
89
90    /// The data path does not exist or cannot be opened.
91    #[error("data path error: {0}")]
92    DataPath(String),
93
94    /// Invalid or corrupt binary data in an espeak-ng-data file.
95    #[error("invalid data: {0}")]
96    InvalidData(String),
97
98    /// A feature of the Rust port has not been implemented yet.
99    ///
100    /// The oracle comparison tests treat this as a "skip" and print the C
101    /// oracle output so you can see what the implementation should produce.
102    #[error("not yet implemented: {0}")]
103    NotImplemented(&'static str),
104
105    /// An I/O error occurred while reading data files.
106    #[error("I/O error: {0}")]
107    Io(#[from] std::io::Error),
108
109    /// The text could not be decoded with the requested encoding.
110    #[error("decoding error at byte offset {offset}: {detail}")]
111    DecodingError {
112        /// Byte offset in the input where the error occurred.
113        offset: usize,
114        /// Human-readable description of the error.
115        detail: String,
116    },
117}
118
119/// Convenience `Result` alias used throughout the crate.
120pub type Result<T> = std::result::Result<T, Error>;