clawft_plugin/voice/
tts.rs1#[derive(Debug, Clone)]
5pub struct TtsResult {
6 pub samples: Vec<f32>,
8 pub sample_rate: u32,
10}
11
12#[derive(Clone)]
14pub struct TtsAbortHandle {
15 cancelled: std::sync::Arc<std::sync::atomic::AtomicBool>,
16}
17
18impl TtsAbortHandle {
19 pub fn new() -> Self {
20 Self {
21 cancelled: std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)),
22 }
23 }
24
25 pub fn cancel(&self) {
26 self.cancelled.store(true, std::sync::atomic::Ordering::SeqCst);
27 }
28
29 pub fn is_cancelled(&self) -> bool {
30 self.cancelled.load(std::sync::atomic::Ordering::SeqCst)
31 }
32}
33
34impl Default for TtsAbortHandle {
35 fn default() -> Self {
36 Self::new()
37 }
38}
39
40pub struct TextToSpeech {
44 model_path: std::path::PathBuf,
45 voice: String,
46 speed: f32,
47}
48
49impl TextToSpeech {
50 pub fn new(model_path: std::path::PathBuf, voice: String, speed: f32) -> Self {
51 Self { model_path, voice, speed }
52 }
53
54 pub fn synthesize(&self, _text: &str) -> Result<TtsResult, String> {
56 Ok(TtsResult {
58 samples: vec![],
59 sample_rate: 16000,
60 })
61 }
62
63 pub fn synthesize_with_abort(
65 &self,
66 _text: &str,
67 _abort: &TtsAbortHandle,
68 ) -> Result<TtsResult, String> {
69 Ok(TtsResult {
71 samples: vec![],
72 sample_rate: 16000,
73 })
74 }
75
76 pub fn model_path(&self) -> &std::path::Path {
77 &self.model_path
78 }
79
80 pub fn voice(&self) -> &str {
81 &self.voice
82 }
83
84 pub fn speed(&self) -> f32 {
85 self.speed
86 }
87}