Skip to main content

Basic Generation

Generate complete audio and receive it all at once:

Playing Audio in Browser

The WAV and PCM decoding utilities expect PCM16 input. For ulaw_8000 or alaw_8000, consume audio.audio or decoded chunk bytes as raw G.711 data.

Streaming Audio

Receive audio chunks as they are generated for lower latency:

Streaming to a Node.js Readable (Vapi / HTTP endpoints)

For server-side integrations that expect a Node.js Readable stream — such as Vapi custom TTS endpoints or Express/Fastify handlers — use client.tts.toReadable() instead of wiring onChunk manually. toReadable() avoids a common race-condition: the stream object is returned before any audio arrives, so you can safely pipe() or attach listeners immediately.
toReadable() is Node.js only. It requires the built-in stream module and will throw in browser environments. Use the callback-based stream() API for browser code.
Call await KugelAudio.create(...) (or await client.connect()) at application startup. This pre-establishes the WebSocket connection so that subsequent toReadable() calls skip the connection overhead and start streaming audio immediately (see Latency).

Processing Audio Chunks

Word Timestamps

Request word-level time alignments alongside audio. Useful for subtitle synchronization, lip-sync, and barge-in handling.

With Generate

With Streaming

Word timestamps add no extra audio latency. They arrive shortly after the corresponding audio chunk — see Latency for typical numbers.

Models

List Available Models

Utility Functions

base64ToArrayBuffer

Convert base64 string to ArrayBuffer:

decodePCM16

Convert base64 PCM16 to Float32Array for Web Audio API:

createWavFile

Create a WAV file from PCM16 data:

createWavBlob

Create a playable Blob from PCM16 data:

client.tts.toReadable (Node.js only)

Convert a TTS stream directly to a Node.js Readable for use in HTTP handlers, pipelines, and server-side integrations. See Streaming to a Node.js Readable for a full example.

For real-time LLM pipelines, use Streaming Sessions instead of one-shot stream(). Input text handling is covered in Text Normalization.