Skip to main content

TtsEngine

Struct TtsEngine 

Source
pub struct TtsEngine { /* private fields */ }
Expand description

Main TTS engine for speech synthesis from GGUF models.

Implementations§

Source§

impl TtsEngine

Source

pub async fn new<P: AsRef<Path>>(gguf_path: P) -> Result<Self>

Create a new TTS engine from a GGUF model file.

§Arguments
  • gguf_path - Path to the Q4 GGUF model file
§Returns

A TTS engine ready for synthesis, or an error if model loading fails.

§Example
use voxtral_tts::TtsEngine;
let tts = TtsEngine::new("models/voxtral-tts-q4.gguf").await?;
Source

pub async fn with_options<P: AsRef<Path>>( gguf_path: P, tokenizer_path: Option<P>, voices_dir: Option<P>, ) -> Result<Self>

Create a new TTS engine with custom options.

§Arguments
  • gguf_path - Path to the Q4 GGUF model file
  • tokenizer_path - Optional path to tokenizer JSON (auto-discovered if None)
  • voices_dir - Optional path to voices directory (defaults to models/voxtral-tts/voice_embedding)
Source

pub fn synthesize( &mut self, text: &str, voice: Option<&str>, ) -> Result<AudioBuffer>

Synthesize speech from text using the default voice (casual_female).

§Arguments
  • text - The text to synthesize
  • voice - Optional voice name (defaults to “casual_female”)
§Returns

An audio buffer containing the synthesized speech at 24kHz.

Source

pub fn synthesize_with_options( &mut self, text: &str, voice: Option<&str>, speed: f32, gain: f32, language: Option<&str>, ) -> Result<AudioBuffer>

Synthesize speech with custom options.

§Arguments
  • text - The text to synthesize
  • voice - Optional voice name (defaults to “casual_female”)
  • speed - Playback speed multiplier (0.5 to 3.0, where 1.0 is normal)
  • gain - Volume gain multiplier (0.1 to 2.0, where 1.0 is normal)
  • language - Optional language code (e.g., “en”, “fr”, “de”)
§Returns

An audio buffer containing the synthesized speech at 24kHz.

§Speed Behavior

Speed adjustment uses resampling which changes both tempo and pitch. Higher speeds result in higher pitch (chipmunk effect), lower speeds result in lower pitch.

§Example
let mut tts = TtsEngine::new("models/voxtral-tts-q4.gguf").await?;
let audio = tts.synthesize_with_options(
    "Hello world!",
    None,      // voice: None = default "casual_female"
    2.0,       // speed: 2.0 = twice as fast
    0.8,       // gain: 0.8 = 20% quieter
    Some("en") // language
)?;
Source

pub fn list_voices(&self) -> Result<Vec<String>>

List available voice presets in the voices directory.

§Returns

A vector of voice names, or an error if the directory doesn’t exist.

Source

pub fn set_max_frames(&mut self, max_frames: usize)

Set the maximum number of audio frames to generate.

Default is 2000 frames. Higher values allow longer audio generation.

Source

pub fn set_euler_steps(&mut self, steps: usize)

Set the number of Euler ODE steps for flow matching (quality vs speed tradeoff).

  • 3 steps: Real-time performance
  • 4 steps: Balanced (default)
  • 8 steps: Higher quality
Source

pub fn save_wav<P: AsRef<Path>>( &self, path: P, audio: &AudioBuffer, ) -> Result<()>

Save audio buffer to a WAV file.

§Arguments
  • path - Output file path
  • audio - Audio buffer to save

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoComptime for T

Source§

fn comptime(self) -> Self

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more