Proxy stream
How to stream audio from a client app to Soniox Speech-to-Text WebSocket API through a proxy server.
Overview
Applies to Text-to-Speech and Speech-to-Text. Examples use Speech-to-Text.
This guide explains how to stream microphone audio from a client to the Soniox WebSocket API through a proxy server.
The client captures audio and sends it over a WebSocket to your proxy server. The proxy opens the Soniox WebSocket with your API key, forwards the audio, and sends the results back to the client.
Use a proxy when you want to inspect, transform, or store audio and transcription data on the server before it reaches the client. The browser never sees a Soniox key, so you need no temporary keys, but every user holds one connection on your server and one from your server to Soniox, and the second counts against your connection limit. If you only want results with the lowest latency, use direct stream instead.
Example
In the following example, we create a proxy HTTP server that:
- Listens for incoming WebSocket connections from the client.
- Forwards audio data from the client to the WebSocket API.
- Relays transcription results back to the client.
The proxy authenticates with your SONIOX_API_KEY, sent in the Authorization header as described in
WebSocket authentication. The browser never sees it. The example
accepts any client; in production, authenticate your own users before you open a Soniox connection
for them.
Python server that will act as a proxy between our client and WebSocket API.
Node.js server that will act as a proxy between our client and WebSocket API.
Next, we create a basic HTML page as the client (same concept works for any other app framework).
The HTML client:
- Connects to the proxy server via WebSocket.
- Captures audio stream from the microphone through the
MediaRecorder. - Streams audio data to the proxy server.
- Receives messages from the proxy server and renders transcribed text into a
div.
Run it
Put index.html in a templates/ folder next to the server, and create a .env file:
Open http://localhost:8000 and click Start.