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,
impl<N> TextToAudioRequest<N, StreamOff>where
N: TextToAudio,
Sourcepub fn with_response_format(self, format: TtsAudioFormat) -> Self
pub fn with_response_format(self, format: TtsAudioFormat) -> Self
Select WAV or PCM for a complete non-streaming response.
Sourcepub fn enable_stream(self) -> TextToAudioRequest<N, StreamOn>
pub fn enable_stream(self) -> TextToAudioRequest<N, StreamOn>
Switch to PCM-only SSE output with base64 payloads by default.
Source§impl<N> TextToAudioRequest<N, StreamOn>where
N: TextToAudio,
impl<N> TextToAudioRequest<N, StreamOn>where
N: TextToAudio,
Sourcepub fn with_encode_format(self, format: TtsEncodeFormat) -> Self
pub fn with_encode_format(self, format: TtsEncodeFormat) -> Self
Select standard base64 or hexadecimal SSE audio payloads.
Sourcepub fn disable_stream(self) -> TextToAudioRequest<N, StreamOff>
pub fn disable_stream(self) -> TextToAudioRequest<N, StreamOff>
Return to non-streaming PCM output and remove encode_format.
Sourcepub async fn stream_via(
&self,
client: &ZaiClient,
) -> ZaiResult<TextToAudioStream>
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,
impl<N, S> TextToAudioRequest<N, S>where
N: TextToAudio,
S: StreamState,
Sourcepub fn body(&self) -> &TextToAudioBody<N>
pub fn body(&self) -> &TextToAudioBody<N>
Borrow the request body without exposing its type-state invariants for mutation.
Sourcepub fn with_input(self, input: impl Into<String>) -> Self
pub fn with_input(self, input: impl Into<String>) -> Self
Set the required input text (1..=1024 Unicode scalar values).
Sourcepub fn with_voice(self, voice: Voice) -> Self
pub fn with_voice(self, voice: Voice) -> Self
Select a built-in or cloned voice.
Sourcepub fn with_speed(self, speed: f32) -> Self
pub fn with_speed(self, speed: f32) -> Self
Set playback speed in 0.5..=2.0.
Sourcepub fn with_volume(self, volume: f32) -> Self
pub fn with_volume(self, volume: f32) -> Self
Set playback volume in 0 < volume <= 10.
Sourcepub fn with_watermark_enabled(self, enabled: bool) -> Self
pub fn with_watermark_enabled(self, enabled: bool) -> Self
Enable or disable the service’s audio watermark.