Speech-to-text
Connect to wss://voice.hams.ai/asr/ws with your API key in the Authorization header (see
Authentication and limits), send audio as binary messages, and read
transcripts back as JSON text messages on the same socket.
Audio format
The frame size is yours to choose: it is simply how much audio you put in each binary message. Smaller frames add WebSocket overhead; larger frames add buffering delay on your side before the audio is sent.
Do not send WAV headers, MP3, Opus, stereo audio, or audio at another sample rate. Decode and resample those formats to headerless 16 kHz mono PCM before sending.
Session options
Immediately after connecting, send these two text messages:
Both default to false for compatibility with older clients, and both apply only to the
connection they are sent on. With the envelope off, the server sends each final transcript as a
bare text message containing only the transcript, and never sends interim results.
Audio can also be sent as a JSON text message, {"type":"audio","audio":"<base64 PCM>"}, which
is what the HAMS STT SDK does. Binary frames are simpler and smaller; both carry the same 16 kHz
mono PCM.
Continuous stream (server VAD on)
Pre-segmented utterances (server VAD off)
Send 20–100 ms frames back-to-back for as long as the stream lasts, at real-time pace. The server finds the start and end of each utterance itself and returns results per utterance. Keep the one socket open for the whole session.
Results
The server returns UTF-8 JSON text messages:
is_final: falseis an interim result. It may change as more audio arrives; use it for live captions and nothing else.is_final: trueis the completed result for the detected utterance.textmay be empty when no speech was recognized.
Use only final results for records and for anything that triggers a business action.
Ending a stream
The last utterance is finalized once the server sees silence after it. Before closing, send about half a second of zero-valued frames, wait for the final result, then close the socket.
Python example
Streams a headerless 16 kHz mono PCM file in real time and prints interim and final results.
To produce audio.pcm from any recording: ffmpeg -i input.wav -f s16le -ar 16000 -ac 1 audio.pcm.