Streaming Audio Detection (WebSocket)
Streaming Audio Detection (WebSocket)
Stream live audio to Resemble Deepfake Detection and receive per-window verdicts while the audio is still arriving. This interface is audio-only and is intended for server-to-server applications such as call monitoring, contact-center analysis, and live media workflows.
WebSocket URL
Authenticate the WebSocket upgrade with your Resemble API key:
The native browser WebSocket() API cannot attach an Authorization header. Connect from a trusted backend or another server-side WebSocket client, and never expose your API key in browser code.
Query Parameters
Only filename and extra_params are accepted. Parameters from the file-based Detect API, including callback_url, visualize, and intelligence, are not supported by the streaming endpoint.
A streaming connection does not create a persisted Detect job. The returned stream_id is not a Detect UUID and cannot be passed to Get Detection. Store any streaming results your application needs after the socket closes.
Audio Format
The recommended wire format is:
- One channel (mono)
- 16,000 Hz sample rate
- Signed 16-bit little-endian PCM
- A PCM WAV header at the beginning of the first binary frame
For a live source whose final length is unknown, the WAV header can use 0xFFFFFFFF for the RIFF and data lengths. Send subsequent PCM audio in binary WebSocket frames. Frames representing approximately 100 milliseconds of audio provide a useful balance between smooth real-time delivery and frame overhead.
The server groups incoming audio into approximately four-second analysis windows. Windows with insufficient voice activity return a skipped result and do not run through the detection model.
Connection Lifecycle
- Open the WebSocket with the bearer authorization header and optional query parameters.
- Wait for the server’s
readymessage before sending audio. - Send the WAV header and PCM samples as binary frames. Read server messages concurrently while uploading.
- Receive a
chunkmessage for each completed analysis window. - Send the text frame
{"type":"end"}after the last audio frame. - Keep the connection open until the server sends
finaland closes the socket with code1000.
Do not close immediately after sending end; queued windows can still be processing.
Server Messages
All server messages are JSON text frames. Clients should ignore unrecognized fields so that compatible fields can be added in the future.
Ready
The first message confirms that the stream can accept audio:
Chunk Result
Each chunk describes one source-time window. On analyzed chunks, the top-level label, aggregated_score, score, and consistency are running metrics across all analyzed windows received so far. The nested chunk_info fields describe only the current window.
Because the stream length is not known in advance, total_chunks is -1. Use chunk_info.begin_timestamp_s and chunk_info.end_timestamp_s to place the result on the original audio timeline. The top-level duration on a chunk is not a final duration; use the duration from the final message.
If a window does not contain enough voice activity, its result uses chunk_label: "skipped" and null top-level metrics:
Final Result
The final message contains the aggregate verdict across all analyzed, voice-active windows:
When no windows contain sufficient voice activity, the server still returns final, with label and aggregated_score set to null, an empty score array, and duration: 0.0.
Error
Errors after the upgrade are delivered as error messages before the socket closes. Authorization errors include an error_code, a human-readable error, and whether reconnecting might succeed without an account change:
Processing errors can instead use error_message. Handle both fields:
Authorization, Session Length, and Usage
Your API key, Deepfake Detection access, plan limits, and available balance are checked when the connection opens. During active streams they are checked again approximately every five minutes, immediately before the next complete analysis window is processed. An idle connection waits until audio resumes before performing the next check.
If access is revoked or the account can no longer run detection, the server stops accepting new analysis work, sends an error, and closes with code 1008. A WebSocket session can remain open for at most 55 minutes. For longer calls, create a new connection before the current session reaches that limit.
Usage is measured from voice-active windows that complete detection. VAD-skipped windows are not counted as analyzed usage. A completed stream with nonzero analyzed duration below two seconds uses the existing two-second minimum billable duration for audio Deepfake Detection.
Handshake Errors
Errors that occur before the WebSocket upgrade are returned as JSON HTTP responses.
WebSocket Close Codes
For a complete runnable client, see Stream Audio for Deepfake Detection.
