Skip to main content

TextToAudioRequest

Struct TextToAudioRequest 

Source
pub struct TextToAudioRequest<N, S = StreamOff>
where N: TextToAudio, S: StreamState,
{ /* private fields */ }
Expand description

Type-state request builder for text-to-speech synthesis.

Non-streaming requests return complete WAV or PCM bytes through send_via. enable_stream switches to PCM-only SSE output decoded by stream_via.

Implementations§

Source§

impl<N> TextToAudioRequest<N, StreamOff>
where N: TextToAudio,

Source

pub fn new(model: N) -> Self

Create a non-streaming TTS request for the selected model.

Source

pub fn with_response_format(self, format: TtsAudioFormat) -> Self

Select WAV or PCM for a complete non-streaming response.

Source

pub fn enable_stream(self) -> TextToAudioRequest<N, StreamOn>

Switch to PCM-only SSE output with base64 payloads by default.

Source

pub async fn send_via(&self, client: &ZaiClient) -> ZaiResult<Bytes>

Submit a non-streaming request and return its complete audio bytes.

Source§

impl<N> TextToAudioRequest<N, StreamOn>
where N: TextToAudio,

Source

pub fn with_encode_format(self, format: TtsEncodeFormat) -> Self

Select standard base64 or hexadecimal SSE audio payloads.

Source

pub fn disable_stream(self) -> TextToAudioRequest<N, StreamOff>

Return to non-streaming PCM output and remove encode_format.

Source

pub async fn stream_via( &self, client: &ZaiClient, ) -> ZaiResult<TextToAudioStream>

Submit the request and yield decoded PCM chunks from its SSE response.

The streaming POST is never retried or redirected. A missing [DONE], malformed encoded chunk, in-band business error, oversized event, or idle timeout is returned once and then terminates the stream.

Source§

impl<N, S> TextToAudioRequest<N, S>
where N: TextToAudio, S: StreamState,

Source

pub fn body(&self) -> &TextToAudioBody<N>

Borrow the request body without exposing its type-state invariants for mutation.

Source

pub fn with_input(self, input: impl Into<String>) -> Self

Set the required input text (1..=1024 Unicode scalar values).

Source

pub fn with_voice(self, voice: Voice) -> Self

Select a built-in or cloned voice.

Source

pub fn with_speed(self, speed: f32) -> Self

Set playback speed in 0.5..=2.0.

Source

pub fn with_volume(self, volume: f32) -> Self

Set playback volume in 0 < volume <= 10.

Source

pub fn with_watermark_enabled(self, enabled: bool) -> Self

Enable or disable the service’s audio watermark.

Source

pub fn validate(&self) -> ZaiResult<()>

Validate all wire constraints without network I/O.

Auto Trait Implementations§

§

impl<N, S> Freeze for TextToAudioRequest<N, S>
where N: Freeze,

§

impl<N, S> RefUnwindSafe for TextToAudioRequest<N, S>

§

impl<N, S> Send for TextToAudioRequest<N, S>
where N: Send, S: Send,

§

impl<N, S> Sync for TextToAudioRequest<N, S>
where N: Sync, S: Sync,

§

impl<N, S> Unpin for TextToAudioRequest<N, S>
where N: Unpin, S: Unpin,

§

impl<N, S> UnsafeUnpin for TextToAudioRequest<N, S>
where N: UnsafeUnpin,

§

impl<N, S> UnwindSafe for TextToAudioRequest<N, S>
where N: UnwindSafe, S: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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