Skip to main content

TtsStream

Struct TtsStream 

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

A streaming text-to-speech session.

TtsStream provides fine-grained control over the TTS process, allowing you to:

  • Send text incrementally
  • Receive audio chunks as they are generated
  • Access timing information for each audio segment

§Example

use gradium::{Client, TtsStream, protocol::tts::Setup};

let client = Client::new("your-api-key");
let setup = Setup::new("m86j6D7UZpGzHsNu");

let mut stream = TtsStream::new(setup, &client).await?;
stream.send_text("Hello, world!").await?;
stream.send_eos().await?;

while let Some(msg) = stream.next_message().await? {
    // Process audio/text messages
}

Implementations§

Source§

impl TtsStream

Source

pub fn split(self) -> (TtsStreamSender, TtsStreamReceiver)

Source

pub async fn new(setup: Setup, client: &Client) -> Result<Self>

Creates a new TTS streaming session.

This establishes a WebSocket connection to the Gradium API and initializes the TTS session with the provided configuration.

§Arguments
  • setup - The TTS configuration (model, voice, output format)
  • client - The Gradium API client
§Returns

A new TtsStream ready to receive text input

§Errors

Returns an error if:

  • The WebSocket connection fails
  • The server returns an error during setup
  • The server sends an unexpected response
Source

pub async fn send_eos(&mut self) -> Result<()>

Signals the end of the text input stream.

After calling this, the server will finish processing any remaining text and send the final audio chunks before closing the stream.

§Errors

Returns an error if the message cannot be sent

Source

pub async fn send_text(&mut self, text: &str) -> Result<()>

Sends text to be synthesized into speech.

You can call this method multiple times to stream text to the TTS engine.

§Arguments
  • text - The text to synthesize
§Errors

Returns an error if the message cannot be sent

Source

pub async fn next_message(&mut self) -> Result<Option<Response>>

Receives the next message from the server.

This can be an audio chunk, text with timing information, or end-of-stream signal.

§Returns
  • Ok(Some(response)) - A message was received
  • Ok(None) - The stream has ended
  • Err(_) - An error occurred
§Errors

Returns an error if:

  • The WebSocket encounters an error
  • The server returns an error response
  • Message deserialization fails
Source

pub fn sample_rate(&self) -> u32

Returns the audio sample rate in Hz.

Source

pub fn frame_size(&self) -> u32

Returns the audio frame size in samples.

Source

pub fn audio_stream_names(&self) -> &[String]

Returns the names of available audio streams.

Source

pub fn text_stream_names(&self) -> &[String]

Returns the names of available text streams.

Source

pub fn request_id(&self) -> &str

Returns the request ID for this session.

Trait Implementations§

Source§

impl Debug for TtsStream

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,