TextToSpeechStream class

Active streaming synthesis session returned by TextToSpeech.synthesizeStream(). Supports both pull-based readNext() and for await (const chunk of stream) iteration, as well as incremental text input via pushText() and finishInput().

Signature:

export declare class TextToSpeechStream implements AsyncIterable<TextToSpeechAudioChunk> 

Implements: AsyncIterable<TextToSpeechAudioChunk>

Methods

Method Modifiers Description
[Symbol.asyncIterator]()
cancel() Cancels this streaming synthesis session immediately.
close() Releases native stream resources.
finishInput() Marks the end of incremental text input on this stream, flushing any remaining partial sentence into the synthesis pipeline.
pushText(textDelta) Appends an incremental text fragment (e.g. from an LLM token stream) to an open stream created with finishInput = false.
readNext() Pulls the next synthesized PCM audio chunk, or returns null when the stream reaches end-of-stream.

TextToSpeechStream.[Symbol.asyncIterator]()

Signature:

[Symbol.asyncIterator](): AsyncIterator<TextToSpeechAudioChunk>;

Returns:

AsyncIterator<TextToSpeechAudioChunk>

TextToSpeechStream.cancel()

Cancels this streaming synthesis session immediately.

Signature:

cancel(): void;

Returns:

void

TextToSpeechStream.close()

Releases native stream resources.

Signature:

close(): void;

Returns:

void

TextToSpeechStream.finishInput()

Marks the end of incremental text input on this stream, flushing any remaining partial sentence into the synthesis pipeline.

Signature:

finishInput(): Promise<void>;

Returns:

Promise<void>

TextToSpeechStream.pushText()

Appends an incremental text fragment (e.g. from an LLM token stream) to an open stream created with finishInput = false.

Signature:

pushText(textDelta: string): Promise<void>;

Parameters

Parameter Type Description
textDelta string The incremental text delta to append.

Returns:

Promise<void>

TextToSpeechStream.readNext()

Pulls the next synthesized PCM audio chunk, or returns null when the stream reaches end-of-stream.

Signature:

readNext(): Promise<TextToSpeechAudioChunk | null>;

Returns:

Promise<TextToSpeechAudioChunk | null>