SonicWeaver

API Documentation

SonicWeaver streams HIPAA-compliant text-to-speech audio over WebSocket. You send text, we send back PCM audio in real time.

Quickstart — 5 minutes

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."))

Authentication

SonicWeaver supports two authentication methods:

MethodHowUse case
API key?api_key=sw_live_...Backend integrations
Firebase token?token=<jwt>Studio web app only
None/v1/stream/demoDemo only (200 char limit)

Get your API key at /developers. Keys do not expire unless revoked.

WebSocket endpoint

Authenticated stream

wss://voice.knewcleus.app/v1/stream?api_key=YOUR_KEY

Full access. Credits deducted. All voices.

Demo stream

wss://voice.knewcleus.app/v1/stream/demo

No auth. 200 character limit. 10 requests/minute per IP.

Protocol — sending and receiving

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"}

Audio format

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")

Available voices

IDNameGenderAccent
af_bellaBellaFemaleUS
af_novaNovaFemaleUS
af_heartHeartFemaleUS
af_sarahSarahFemaleUS
am_michaelMichaelMaleUS
am_adamAdamMaleUS
am_echoEchoMaleUS
bf_emmaEmmaFemaleBritish
bm_georgeGeorgeMaleBritish
bm_danielDanielMaleBritish

List voices programmatically: GET https://voice.knewcleus.app/v1/voices

Error codes

CodeMeaning
authInvalid or missing API key / token
too_many_connectionsConcurrent stream limit reached for your plan
insufficient_creditsMonthly credit limit reached
monthly_capMonthly usage cap reached
rate_limitedDemo endpoint rate limit (10 req/min per IP)
bad_requestInvalid JSON in request
synthesis_errorAudio generation failed for a chunk
server_errorUnexpected server error

Errors arrive as JSON on the WebSocket before it closes:

{"type": "error", "code": "insufficient_credits", "message": "No credits remaining."}

Plans and limits

PlanPriceMinutesStreamsHIPAA BAA
Free$0/mo101
Creator$29/mo5003
Studio$149/mo3,00010
Growth API$999/mo50,00025
Scale API$4,999/mo300,000100

Overage on Studio: $0.015/min · Growth API: $0.018/min