Installation
Initialization
Transport protocol:
"websocket" for real-time streaming, or "http" for REST API.Protocol comparison
Use WebSocket (default) for real-time streaming and low-latency playback. Use HTTP when you need
voiceReference for instant voice cloning or sampleRate with non-mp3 formats.
Connection
For WebSocket protocol, you must callconnect() before generating audio:
Stream audio (default, fastest)
asyncTts() yields audio chunks while they are still being generated, so playback can start right away. Keep the connection open and reuse it for the next request.
Buffer — audio chunks as they are generated. The first chunk carries the WAV header.
To call the same API without the SDK, see Generate Audio Streamed.
Generate to buffer
Generate audio and receive aBuffer of WAV data:
Promise<Buffer> — WAV audio data.
Generate to file
Generate audio and save directly to a file:Promise<void>
Generation parameters
BothgenerateToBuffer and generateToFile accept these options:
Sample rate in Hz. WebSocket protocol only supports this with
mp3 format. Use HTTP protocol for other formats.When
true, chunks passed to onChunk have WAV headers stripped (raw PCM). WebSocket protocol only.