diff options
| author | soryu <soryu@soryu.co> | 2026-01-28 03:49:13 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-01-28 03:49:54 +0000 |
| commit | d0436686f047f1d82c30da26cf83f9eca6727292 (patch) | |
| tree | f4f7b6bc7c6cc410d90908d3adf7c519bdf6a2ad /makima/src/tts/mod.rs | |
| parent | c3de071511de5e8a8d63ea4ca47c815cb6450215 (diff) | |
| download | soryu-d0436686f047f1d82c30da26cf83f9eca6727292.tar.gz soryu-d0436686f047f1d82c30da26cf83f9eca6727292.zip | |
feat: add inference cancellation support for TTS generation
Add cooperative cancellation via Arc<AtomicBool> cancel flag that
threads through TtsEngine::generate -> Qwen3Tts -> GenerationContext.
The autoregressive loop and streaming decoder check the flag each
iteration and break early when set. The speak WebSocket handler
creates a per-session flag, passes it to generate, and sets it on
Cancel/Stop/Close messages.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'makima/src/tts/mod.rs')
| -rw-r--r-- | makima/src/tts/mod.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/makima/src/tts/mod.rs b/makima/src/tts/mod.rs index 2cd0412..b66f4a5 100644 --- a/makima/src/tts/mod.rs +++ b/makima/src/tts/mod.rs @@ -5,6 +5,8 @@ //! - **Qwen3**: Pure Rust candle-based Qwen3-TTS-12Hz-0.6B use std::path::Path; +use std::sync::atomic::AtomicBool; +use std::sync::Arc; pub mod chatterbox; pub mod qwen3; @@ -109,11 +111,17 @@ pub enum TtsBackend { #[async_trait::async_trait] pub trait TtsEngine: Send + Sync { /// Generate complete audio from text with a voice reference. + /// + /// The optional `cancel_flag` can be set to `true` by another thread/task + /// to request early termination of the generation loop. Engines that + /// support cancellation will check this flag periodically and return + /// whatever audio has been produced so far. async fn generate( &self, text: &str, reference_audio: Option<&[f32]>, reference_sample_rate: Option<u32>, + cancel_flag: Option<Arc<AtomicBool>>, ) -> Result<Vec<AudioChunk>, TtsError>; /// Check if the engine is loaded and ready. |
