File size: 2,884 Bytes
6b408d7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""

Custom exceptions for VoiceAuth API.



Provides specific exception types for different error scenarios.

"""


class VoiceAuthError(Exception):
    """Base exception for all VoiceAuth errors."""

    def __init__(self, message: str, details: dict | None = None) -> None:
        """

        Initialize VoiceAuthError.



        Args:

            message: Human-readable error message

            details: Additional error details

        """
        super().__init__(message)
        self.message = message
        self.details = details or {}


class AudioDecodeError(VoiceAuthError):
    """

    Raised when Base64 audio decoding fails.



    This typically occurs when:

    - The input is not valid Base64

    - The decoded data is corrupted

    """

    pass


class AudioFormatError(VoiceAuthError):
    """

    Raised when audio format is invalid or unsupported.



    This typically occurs when:

    - The audio is not a valid MP3 file

    - The audio codec is unsupported

    - The file header is corrupted

    """

    pass


class AudioDurationError(VoiceAuthError):
    """

    Raised when audio duration is out of allowed bounds.



    This typically occurs when:

    - Audio is shorter than minimum duration

    - Audio is longer than maximum duration

    """

    def __init__(

        self,

        message: str,

        duration: float | None = None,

        min_duration: float | None = None,

        max_duration: float | None = None,

    ) -> None:
        """

        Initialize AudioDurationError.



        Args:

            message: Human-readable error message

            duration: Actual duration of the audio

            min_duration: Minimum allowed duration

            max_duration: Maximum allowed duration

        """
        details = {}
        if duration is not None:
            details["duration"] = duration
        if min_duration is not None:
            details["min_duration"] = min_duration
        if max_duration is not None:
            details["max_duration"] = max_duration
        super().__init__(message, details)


class AudioProcessingError(VoiceAuthError):
    """

    Raised when audio processing fails.



    This is a general error for audio processing issues

    that don't fit into more specific categories.

    """

    pass


class ModelNotLoadedError(VoiceAuthError):
    """

    Raised when attempting to use an unloaded model.



    This typically occurs when:

    - The model failed to load on startup

    - The model was unloaded due to memory pressure

    """

    pass


class InferenceError(VoiceAuthError):
    """

    Raised when ML model inference fails.



    This typically occurs when:

    - The input tensor is malformed

    - GPU memory is exhausted

    - Model internal error

    """

    pass