fleetforge_runtime/gateway/
speech.rs

1//! Speech adapter traits for voice and transcription integrations.
2
3use anyhow::Result;
4use async_trait::async_trait;
5
6/// Adapter that transcribes audio into text.
7#[async_trait]
8pub trait SpeechToText: Send + Sync {
9    async fn transcribe(&self, audio_bytes: &[u8], lang: Option<&str>) -> Result<String>;
10}
11
12/// Adapter that synthesises speech audio from text.
13#[async_trait]
14pub trait TextToSpeech: Send + Sync {
15    async fn synthesize(&self, text: &str, voice: Option<&str>) -> Result<Vec<u8>>;
16}
17
18/// No-op transcription adapter suitable for tests and offline demos.
19pub struct NoopStt;
20
21#[async_trait]
22impl SpeechToText for NoopStt {
23    async fn transcribe(&self, _audio: &[u8], _lang: Option<&str>) -> Result<String> {
24        Ok(String::from("transcript (noop)"))
25    }
26}
27
28/// No-op synthesis adapter that returns fake audio bytes.
29pub struct NoopTts;
30
31#[async_trait]
32impl TextToSpeech for NoopTts {
33    async fn synthesize(&self, text: &str, _voice: Option<&str>) -> Result<Vec<u8>> {
34        Ok(format!("AUDIO({})", text).into_bytes())
35    }
36}