#[derive(Debug, Clone)]
pub struct TtsResult {
pub samples: Vec<f32>,
pub sample_rate: u32,
}
#[derive(Clone)]
pub struct TtsAbortHandle {
cancelled: std::sync::Arc<std::sync::atomic::AtomicBool>,
}
impl TtsAbortHandle {
pub fn new() -> Self {
Self {
cancelled: std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)),
}
}
pub fn cancel(&self) {
self.cancelled.store(true, std::sync::atomic::Ordering::SeqCst);
}
pub fn is_cancelled(&self) -> bool {
self.cancelled.load(std::sync::atomic::Ordering::SeqCst)
}
}
impl Default for TtsAbortHandle {
fn default() -> Self {
Self::new()
}
}
pub struct TextToSpeech {
model_path: std::path::PathBuf,
voice: String,
speed: f32,
}
impl TextToSpeech {
pub fn new(model_path: std::path::PathBuf, voice: String, speed: f32) -> Self {
Self { model_path, voice, speed }
}
pub fn synthesize(&self, _text: &str) -> Result<TtsResult, String> {
Ok(TtsResult {
samples: vec![],
sample_rate: 16000,
})
}
pub fn synthesize_with_abort(
&self,
_text: &str,
_abort: &TtsAbortHandle,
) -> Result<TtsResult, String> {
Ok(TtsResult {
samples: vec![],
sample_rate: 16000,
})
}
pub fn model_path(&self) -> &std::path::Path {
&self.model_path
}
pub fn voice(&self) -> &str {
&self.voice
}
pub fn speed(&self) -> f32 {
self.speed
}
}