Skip to main content

TtsEngine

Trait TtsEngine 

Source
pub trait TtsEngine:
    Send
    + Sync
    + Debug {
    // Required methods
    fn speak(
        &self,
        text: &str,
        voice: Option<&str>,
        rate: f32,
        pitch: f32,
        volume: f32,
        on_audio: Option<OnAudioCallback<'_>>,
        on_boundary: Option<OnBoundaryCallback<'_>>,
    ) -> TtsResult<()>;
    fn speak_sync(
        &self,
        text: &str,
        voice: Option<&str>,
        rate: f32,
        pitch: f32,
        volume: f32,
        on_audio: Option<OnAudioCallback<'_>>,
        on_boundary: Option<OnBoundaryCallback<'_>>,
    ) -> TtsResult<()>;
    fn stop(&self) -> TtsResult<()>;
    fn get_voices(&self) -> TtsResult<Vec<Voice>>;
    fn engine_id(&self) -> &'static str;

    // Provided methods
    fn speak_with_options(
        &self,
        text: &str,
        options: Option<&SpeakOptions>,
        on_audio: Option<OnAudioCallback<'_>>,
        on_boundary: Option<OnBoundaryCallback<'_>>,
    ) -> TtsResult<()> { ... }
    fn pause(&self) -> TtsResult<()> { ... }
    fn resume(&self) -> TtsResult<()> { ... }
    fn check_credentials(&self) -> TtsResult<bool> { ... }
    fn synth_to_bytes(
        &self,
        text: &str,
        voice: Option<&str>,
        rate: f32,
        pitch: f32,
        volume: f32,
    ) -> TtsResult<Vec<u8>> { ... }
    fn synth_to_bytes_with_options(
        &self,
        text: &str,
        options: Option<&SpeakOptions>,
    ) -> TtsResult<Vec<u8>> { ... }
    fn synth_with_boundaries(
        &self,
        text: &str,
        voice: Option<&str>,
        rate: f32,
        pitch: f32,
        volume: f32,
    ) -> TtsResult<(Vec<u8>, Vec<WordBoundary>)> { ... }
}
Expand description

Trait that every TTS engine must implement.

Mirrors Swift’s TTSClient protocol.

Required Methods§

Source

fn speak( &self, text: &str, voice: Option<&str>, rate: f32, pitch: f32, volume: f32, on_audio: Option<OnAudioCallback<'_>>, on_boundary: Option<OnBoundaryCallback<'_>>, ) -> TtsResult<()>

Start speaking text asynchronously.

Source

fn speak_sync( &self, text: &str, voice: Option<&str>, rate: f32, pitch: f32, volume: f32, on_audio: Option<OnAudioCallback<'_>>, on_boundary: Option<OnBoundaryCallback<'_>>, ) -> TtsResult<()>

Speak text synchronously, blocking until synthesis completes.

Source

fn stop(&self) -> TtsResult<()>

Stop any in-progress speech.

Source

fn get_voices(&self) -> TtsResult<Vec<Voice>>

List available voices for this engine.

Source

fn engine_id(&self) -> &'static str

Return the unique identifier of this engine (e.g. "system", "sherpaonnx").

Provided Methods§

Source

fn speak_with_options( &self, text: &str, options: Option<&SpeakOptions>, on_audio: Option<OnAudioCallback<'_>>, on_boundary: Option<OnBoundaryCallback<'_>>, ) -> TtsResult<()>

Speak with full SpeakOptions, matching Swift’s speak(_:options:).

Source

fn pause(&self) -> TtsResult<()>

Pause speech (default: no-op, engines may override).

Source

fn resume(&self) -> TtsResult<()>

Resume speech (default: no-op, engines may override).

Source

fn check_credentials(&self) -> TtsResult<bool>

Check whether the configured credentials are valid. Default: attempt to fetch voices as a validation.

Source

fn synth_to_bytes( &self, text: &str, voice: Option<&str>, rate: f32, pitch: f32, volume: f32, ) -> TtsResult<Vec<u8>>

Synthesize text to audio bytes (full buffer, no playback). Mirrors Swift’s synthToBytes(_:options:).

Source

fn synth_to_bytes_with_options( &self, text: &str, options: Option<&SpeakOptions>, ) -> TtsResult<Vec<u8>>

Synthesize with SpeakOptions.

Source

fn synth_with_boundaries( &self, text: &str, voice: Option<&str>, rate: f32, pitch: f32, volume: f32, ) -> TtsResult<(Vec<u8>, Vec<WordBoundary>)>

Synthesize text and return word boundary information.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§