SonicWeaver streams HIPAA-compliant text-to-speech audio over WebSocket. You send text, we send back PCM audio in real time.
On this page
No SDK required. Just Python and a WebSocket library.
1. Install dependencies
pip install websockets
2. Test the demo endpoint — no account needed
import asyncio, websockets, json
async def demo():
uri = "wss://voice.knewcleus.app/v1/stream/demo"
async with websockets.connect(uri) as ws:
await ws.send(json.dumps({
"text": "Hello from SonicWeaver.",
"voice": "af_bella"
}))
async for msg in ws:
if isinstance(msg, bytes):
print(f"Audio chunk: {len(msg)} bytes")
elif json.loads(msg).get("type") == "done":
print("Done.")
break
asyncio.run(demo())3. Get your API key
Sign up at sonicweaver.knewcleus.app/login then go to /developers to generate your key.
4. Authenticate and stream
import asyncio, websockets, json
API_KEY = "sw_live_your_key_here"
async def synthesize(text: str, voice: str = "af_bella") -> bytes:
uri = f"wss://voice.knewcleus.app/v1/stream?api_key={API_KEY}"
pcm = []
async with websockets.connect(uri) as ws:
await ws.send(json.dumps({"text": text, "voice": voice}))
async for msg in ws:
if isinstance(msg, bytes):
pcm.append(msg)
else:
data = json.loads(msg)
if data.get("type") == "done":
print(f"Credits remaining: {data.get('credits_remaining')}")
break
if data.get("type") == "error":
raise Exception(data.get("message"))
return b"".join(pcm) # Raw PCM — see Audio Format section
asyncio.run(synthesize("Your appointment is tomorrow at 2 PM."))SonicWeaver supports two authentication methods:
| Method | How | Use case |
|---|---|---|
| API key | ?api_key=sw_live_... | Backend integrations |
| Firebase token | ?token=<jwt> | Studio web app only |
| None | /v1/stream/demo | Demo only (200 char limit) |
Get your API key at /developers. Keys do not expire unless revoked.
Authenticated stream
wss://voice.knewcleus.app/v1/stream?api_key=YOUR_KEYFull access. Credits deducted. All voices.
Demo stream
wss://voice.knewcleus.app/v1/stream/demoNo auth. 200 character limit. 10 requests/minute per IP.
You send (JSON):
{
"text": "Your text here", // required, max 10,000 chars
"voice": "af_bella", // optional, default af_bella
"resume_index": 0 // optional, for reconnection
}You receive:
chunk_start (JSON)
Sent before each audio chunk.
{"type": "chunk_start", "index": 0, "is_last": false}audio (binary)
Raw PCM audio bytes. Play or buffer these.
<binary PCM data — see Audio Format>done (JSON)
Sent when all audio has been streamed.
{"type": "done", "credits_remaining": 499850}error (JSON)
Sent on failure. Connection closes after.
{"type": "error", "code": "insufficient_credits", "message": "..."}ping (JSON)
Keepalive sent every 20s on long requests.
{"type": "ping"}Format
Raw PCM (not WAV, not MP3)
Encoding
Signed 16-bit little-endian (s16le)
Sample rate
24,000 Hz
Channels
Mono (1 channel)
To save as a WAV file (Python):
import struct
def pcm_to_wav(pcm: bytes, filename: str):
sr, ch, bd = 24000, 1, 16
with open(filename, "wb") as f:
f.write(b"RIFF")
f.write(struct.pack("<I", 36 + len(pcm)))
f.write(b"WAVE")
f.write(b"fmt ")
f.write(struct.pack("<I", 16))
f.write(struct.pack("<H", 1))
f.write(struct.pack("<H", ch))
f.write(struct.pack("<I", sr))
f.write(struct.pack("<I", sr * ch * bd // 8))
f.write(struct.pack("<H", ch * bd // 8))
f.write(struct.pack("<H", bd))
f.write(b"data")
f.write(struct.pack("<I", len(pcm)))
f.write(pcm)
pcm_to_wav(pcm_bytes, "output.wav")| ID | Name | Gender | Accent |
|---|---|---|---|
af_bella | Bella | Female | US |
af_nova | Nova | Female | US |
af_heart | Heart | Female | US |
af_sarah | Sarah | Female | US |
am_michael | Michael | Male | US |
am_adam | Adam | Male | US |
am_echo | Echo | Male | US |
bf_emma | Emma | Female | British |
bm_george | George | Male | British |
bm_daniel | Daniel | Male | British |
List voices programmatically: GET https://voice.knewcleus.app/v1/voices
| Code | Meaning |
|---|---|
auth | Invalid or missing API key / token |
too_many_connections | Concurrent stream limit reached for your plan |
insufficient_credits | Monthly credit limit reached |
monthly_cap | Monthly usage cap reached |
rate_limited | Demo endpoint rate limit (10 req/min per IP) |
bad_request | Invalid JSON in request |
synthesis_error | Audio generation failed for a chunk |
server_error | Unexpected server error |
Errors arrive as JSON on the WebSocket before it closes:
{"type": "error", "code": "insufficient_credits", "message": "No credits remaining."}| Plan | Price | Minutes | Streams | HIPAA BAA |
|---|---|---|---|---|
| Free | $0/mo | 10 | 1 | — |
| Creator | $29/mo | 500 | 3 | — |
| Studio | $149/mo | 3,000 | 10 | ✓ |
| Growth API | $999/mo | 50,000 | 25 | ✓ |
| Scale API | $4,999/mo | 300,000 | 100 | ✓ |
Overage on Studio: $0.015/min · Growth API: $0.018/min