Any other value of
encoding, sample_rate or channels is refused before the upgrade with HTTP 400 {"error":"invalid_audio_format","message":"…"}. On success the server answers 101 Switching Protocols with the response header jamie-session-id: ps_<32 hex>; the same id also arrives in the first message.
Sending audio
- Send audio as binary messages of raw
pcm_s16le, 16 kHz, mono. Frames are concatenated into one continuous stream, so they do not have to align with samples. - Use frames of 100 ms (3,200 bytes). A frame may hold at most 500 ms (16,000 bytes); a larger one gets the error
frame_too_largeand the socket closes with1009. The session itself stays open and you can reconnect. A message over 1 MiB drops the connection without an error message. - Stream in real time. In total you may be at most 500 ms ahead of the wall-clock time since the session started (plus 0.1 % of the elapsed time, for clock drift). Sending faster ends the session with
ahead_of_realtimeand close4003; you still receive the final result. For a pre-recorded file, pace the frames at 100 ms per 3,200 bytes. - For a new session, send only audio captured after the
sessionmessage. Audio you buffered while connecting would put you ahead of real time immediately; drop it. After a reconnect it is the other way round: send the audio you buffered while disconnected. - Keep the socket alive. If nothing arrives from you for 60 s, the server sends
client_inactiveand closes with4004. If you pause audio, send{"type":"keepalive"}at least every 30 s; do not rely on WebSocket pings. The session stays open and you can reconnect. - Give pings at least 60 s. If your WebSocket library sends pings, allow at least 60 s for the reply. A network path can hold back a connection for 20–30 s and then deliver everything at once; a shorter ping timeout closes a session that would have recovered. If the connection drops anyway (
1005,1006), reconnect with the session id.
Client messages
Audio sent after
finalize is ignored, except that a frame over 16,000 bytes still closes the connection with 1009; reconnect with the session id to receive the result.
Ending a session
Send{"type":"finalize"} (or an empty binary frame), keep reading, and wait for the server to close. You receive, in order: a last speakers message with the remaining segments and "open":null, then final, then finished, then close 1000. This usually takes under a second; allow up to 60 s before giving up. If the server cannot finish in time you receive result_incomplete, followed by final with everything decided so far.
Closing the socket yourself does not end the session: it stays open for reconnection for 300 s and then ends as
idle_timeout. Once you send a close frame, nothing more is delivered on that connection. If you close before finished: when you had already sent finalize, reconnect with the session id to receive final and finished; when you had not, reconnecting rejoins the running session, and you end it by sending finalize there.
