1use thiserror::Error;
6
7#[derive(Error, Debug)]
9pub enum Error {
10 #[cfg(feature = "audio")]
12 #[error("音频错误: {0}")]
13 Audio(rs_voice_toolkit_audio::AudioError),
14
15 #[cfg(feature = "stt")]
17 #[error("语音识别错误: {0}")]
18 Stt(rs_voice_toolkit_stt::SttError),
19
20 #[cfg(feature = "tts")]
22 #[error("语音合成错误: {0}")]
23 Tts(rs_voice_toolkit_tts::TtsError),
24
25 #[error("IO错误: {0}")]
27 Io(#[from] std::io::Error),
28
29 #[error("其他错误: {0}")]
31 Other(String),
32}
33
34pub type Result<T> = std::result::Result<T, Error>;
36
37impl Error {
39 pub fn other<S: Into<String>>(msg: S) -> Self {
41 Error::Other(msg.into())
42 }
43}
44
45impl From<String> for Error {
47 fn from(err: String) -> Self {
48 Error::Other(err)
49 }
50}
51
52impl From<&str> for Error {
54 fn from(err: &str) -> Self {
55 Error::Other(err.to_string())
56 }
57}
58
59#[cfg(feature = "stt")]
61impl From<rs_voice_toolkit_stt::SttError> for Error {
62 fn from(err: rs_voice_toolkit_stt::SttError) -> Self {
63 Error::Stt(err)
64 }
65}
66
67#[cfg(feature = "audio")]
69impl From<rs_voice_toolkit_audio::AudioError> for Error {
70 fn from(err: rs_voice_toolkit_audio::AudioError) -> Self {
71 Error::Audio(err)
72 }
73}
74
75#[cfg(feature = "tts")]
77impl From<rs_voice_toolkit_tts::TtsError> for Error {
78 fn from(err: rs_voice_toolkit_tts::TtsError) -> Self {
79 Error::Tts(err)
80 }
81}