voice_toolkit/
lib.rs

1//! Rust 语音工具库
2//!
3//! 提供语音转文本(STT)和文本转语音(TTS)功能的统一接口
4
5// 导入错误处理模块
6mod error;
7pub use error::{Error, Result};
8
9// 重新导出各个模块
10#[cfg(feature = "stt")]
11pub use rs_voice_toolkit_stt as stt;
12
13#[cfg(feature = "audio")]
14pub use rs_voice_toolkit_audio as audio;
15
16#[cfg(feature = "tts")]
17pub use rs_voice_toolkit_tts as tts;
18
19// 重新导出常用的类型和函数
20#[cfg(feature = "stt")]
21pub use rs_voice_toolkit_stt::transcribe_file;
22
23#[cfg(all(feature = "stt", feature = "streaming"))]
24pub use rs_voice_toolkit_stt::streaming::StreamingTranscriber;
25
26// 统一错误处理包装函数
27#[cfg(feature = "stt")]
28mod stt_wrappers {
29    use super::*;
30    
31    /// 转录文件(统一错误处理)
32    pub async fn transcribe_file_unified<P1, P2>(
33        model_path: P1,
34        audio_path: P2,
35    ) -> Result<crate::stt::TranscriptionResult>
36    where
37        P1: Into<std::path::PathBuf>,
38        P2: AsRef<std::path::Path>,
39    {
40        crate::stt::transcribe_file(model_path, audio_path)
41            .await
42            .map_err(Error::from)
43    }
44}
45
46// 导出统一错误处理函数
47#[cfg(feature = "stt")]
48pub use stt_wrappers::transcribe_file_unified;