For the complete documentation index, see llms.txt. This page is also available as Markdown.

aiSpeakStream

aiSpeakStream() streams synthesized speech to a callback as it is generated.

Stream text-to-speech audio from an AI provider as it is generated. See Streaming Text-to-Speech for the full guide.

Syntax

summary = aiSpeakStream( text, callback, params={}, options={} )

Parameters

Parameter
Type
Required
Description

text

string

✅ Yes

The text to synthesize. Must not be empty

callback

function

✅ Yes

Called with each event struct. Return false to stop early and close the provider connection

params

struct

No

Provider parameters: model, voice (or voice_id), sample_rate, language, add_timestamps, transport (Cartesia)

options

struct

No

provider, apiKey, outputFormat, speed, timeout (idle timeout in seconds, default 30), logging

Callback events

type

Fields

audio

data (binary), format, sampleRate, sequence

timestamps

words, start, end

done

chunks, bytes (always last)

Returns

A struct: { provider, model, audioFormat, sampleRate, chunks, bytes, completed }. completed is false when the callback stopped the stream.

Throws

Type
When

UnsupportedCapability

The provider does not support streaming speech

InvalidArgument

Empty text, unsupported format, or invalid transport

ProviderError

The provider returned an error

Examples

Providers

Cartesia, ElevenLabs, OpenAI, Mistral and Gemini stream. Grok does not (WebSocket only). Check with aiService( "cartesia" ).hasCapability( "speechStream" ).

See Also

Last updated