rime.v1.json on wss://api.rime.ai/coda/ws. For the Protobuf variant, use the Protobuf quickstart.
Prepare the client
Install uv and Python 3.11 or later. Create a Rime API key, then setRIME_API_KEY in your server’s environment. Keep the key out of browser code and source control.
Create a project and install the WebSocket client:
Stream audio to a file
Save this asstream_json.py. It overwrites output.pcm in the current directory. The sender and receiver run together so audio can arrive while the client sends more text.
Saved output.pcm. The file contains raw mono, signed 16-bit little-endian PCM at 24 kHz, with no WAV header. A failed run can leave a partial file.
To stream input over time, replace the fixed list in send_sentences with complete sentences from your application. To route audio to a browser, phone system, or player, replace output.write(...) with your audio handler.
The script closes the connection after done. In a persistent application, keep the socket open and start the next turn with a new contextId. Use one receive loop to dispatch events across turns. See lifecycle and interruption handling.
Run the audio demo
Download the audio demos, extract the archive, and open itscoda-audio-demos directory. With RIME_API_KEY set and a local audio output device available, run:
Playback complete after the last samples play. The archive includes the playback helper and a README with audio-device setup and troubleshooting.
Use another language or audio format
Setlanguage and speaker together for the desired voice. Set the audio MIME type in audioParameters.audioFormat. Every JSON audio payload is base64 regardless of the selected audio format. Decode it once, then send the bytes to the appropriate player or decoder.
The audio demo accepts only raw PCM. For live playback of MP3, Opus, or WAV, use a streaming decoder for that format and keep it open for the whole context. See audio parameters for sample rates and byte formats.
