Skip to main content

flexaudio_core/
whisper_error.rs

1//! Stable optional-processor failure codes, independent of inference dependencies.
2
3/// Typed cause of an isolated Whisper VAD failure.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum WhisperCode {
6    /// A segmentation parameter is outside the supported domain.
7    InvalidParameter,
8    /// An inference probability is not finite or normalized.
9    InvalidProbability,
10    /// PCM is not finite or normalized.
11    InvalidPcm,
12    /// Checked arithmetic or storage capacity was exceeded.
13    Overflow,
14    /// Processing followed a completed session without reset.
15    SessionFinished,
16    /// Inference or model reset failed.
17    Inference,
18    /// The embedded model could not be constructed.
19    ModelLoad,
20    /// A previous failure requires a successful reset.
21    FailedSession,
22    /// Capture input did not contain complete stereo frames.
23    InvalidStereoLength,
24    /// A capture sample count exceeded the supported domain.
25    CaptureSampleOverflow,
26    /// The capture timestamp exceeded its supported domain.
27    PtsOutOfRange,
28    /// Conversion could not establish an exact sample-aligned clock.
29    UnsupportedConversionClock,
30    /// Capture conversion failed.
31    Conversion,
32    /// Processing followed stopped capture intake.
33    Stopped,
34}
35
36impl WhisperCode {
37    /// Stable code spelling shared by language bindings.
38    pub fn as_str(self) -> &'static str {
39        match self {
40            Self::InvalidParameter => "InvalidParameter",
41            Self::InvalidProbability => "InvalidProbability",
42            Self::InvalidPcm => "InvalidPcm",
43            Self::Overflow => "Overflow",
44            Self::SessionFinished => "SessionFinished",
45            Self::Inference => "Inference",
46            Self::ModelLoad => "ModelLoad",
47            Self::FailedSession => "FailedSession",
48            Self::InvalidStereoLength => "InvalidStereoLength",
49            Self::CaptureSampleOverflow => "CaptureSampleOverflow",
50            Self::PtsOutOfRange => "PtsOutOfRange",
51            Self::UnsupportedConversionClock => "UnsupportedConversionClock",
52            Self::Conversion => "Conversion",
53            Self::Stopped => "Stopped",
54        }
55    }
56
57    /// Safe explanation of why this processor failed; contains no input or device details.
58    pub fn explanation(self) -> &'static str {
59        match self {
60            Self::InvalidParameter => "a segmentation parameter is outside the supported domain",
61            Self::InvalidProbability => "an inference probability is not finite or normalized",
62            Self::InvalidPcm => "PCM contains a nonfinite or out-of-range sample",
63            Self::Overflow => "checked arithmetic or storage exceeds the supported domain",
64            Self::SessionFinished => {
65                "the completed session requires a successful reset before processing"
66            }
67            Self::Inference => "model inference or reset could not complete",
68            Self::ModelLoad => "the embedded model could not be constructed",
69            Self::FailedSession => "a previous processor failure requires a successful reset",
70            Self::InvalidStereoLength => "capture input does not contain complete stereo frames",
71            Self::CaptureSampleOverflow => "the capture sample count exceeds the supported domain",
72            Self::PtsOutOfRange => "the capture timestamp exceeds the supported domain",
73            Self::UnsupportedConversionClock => {
74                "conversion cannot establish an exact sample-aligned clock"
75            }
76            Self::Conversion => "capture conversion could not preserve the valid sample timeline",
77            Self::Stopped => "capture intake has already stopped",
78        }
79    }
80}