Placeholders
The snippets below use these placeholders. Replace them before running the code.| Placeholder | Replace with |
|---|---|
SLNG_API_KEY | An SLNG key from app.slng.ai/api-keys. The snippets read it from the SLNG_API_KEY environment variable. |
Message Flow
Every TTS WebSocket session follows this pattern: For the full list of message types and parameters, see the WebSocket protocol reference. To keep acronyms, names, and domain terms consistent during synthesis, set a session default or per-turn pronunciation dictionary.Quick Start
Connect, initialize a session, send text, and save the audio to a file. Both examples write aoutput.pcm file containing raw 16-bit PCM audio at 24 kHz. You can play it with ffplay:
More Examples
Batch Text Streaming
Send multiple sentences for smoother speech instead of one large block. This is a complete example you can run independently.Next Steps
Live TTS demo
Try real-time TTS in your browser, no setup needed
WebSocket protocol
Full message types, parameters, and error codes
Pronunciation dictionaries
Reuse pronunciation rules across TTS requests
TTS HTTP examples
Simpler integration for non-streaming use cases
TTS API reference
Endpoint-specific parameters