Skip to main content

qwen3_asr/
lib.rs

1mod config;
2mod decoder;
3mod encoder;
4mod error;
5#[cfg(feature = "hub")]
6pub(crate) mod hub;
7mod inference;
8mod linear;
9mod mel;
10mod streaming;
11
12pub use encoder::EncoderCache;
13pub use error::{AsrError, Result};
14pub use inference::{AsrInference, TranscribeOptions, TranscribeResult};
15pub use mel::load_audio_wav;
16pub use streaming::{StreamingOptions, StreamingState};
17
18/// Select the best available device: CUDA (if `cuda` feature) → Metal (if `metal` feature) → CPU.
19///
20/// Logs the selected device at `info` level and any fallback at `warn` level.
21pub fn best_device() -> candle_core::Device {
22    #[cfg(feature = "cuda")]
23    {
24        match candle_core::Device::new_cuda(0) {
25            Ok(device) => {
26                log::info!("Using CUDA device 0");
27                return device;
28            }
29            Err(e) => {
30                log::warn!("CUDA feature enabled but device creation failed: {e}, falling back");
31            }
32        }
33    }
34    #[cfg(feature = "metal")]
35    {
36        match candle_core::Device::new_metal(0) {
37            Ok(device) => {
38                log::info!("Using Metal device");
39                return device;
40            }
41            Err(e) => {
42                log::warn!("Metal feature enabled but device creation failed: {e}, falling back");
43            }
44        }
45    }
46    log::info!("Using CPU device");
47    candle_core::Device::Cpu
48}