use async_trait::async_trait;
use pipecrab_core::AudioFormat;
use pipecrab_runtime::MaybeSendSync;
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait Transcriber: MaybeSendSync {
async fn transcribe(&self, samples: &[f32], format: AudioFormat) -> Result<String, SttError>;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SttError {
Engine(String),
UnsupportedFormat {
expected: AudioFormat,
got: AudioFormat,
},
}
impl std::fmt::Display for SttError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
SttError::Engine(msg) => write!(f, "stt engine error: {msg}"),
SttError::UnsupportedFormat { expected, got } => write!(
f,
"stt format mismatch: transcriber expects {} Hz/{} ch, got {} Hz/{} ch",
expected.sample_rate, expected.channels, got.sample_rate, got.channels,
),
}
}
}
impl std::error::Error for SttError {}