rime.v1.binary and writes PCM audio chunks to a file as they arrive. It needs no audio device. The endpoint, synthesis parameters, and lifecycle are the same as in the JSON quickstart.
Prepare the client
Install uv and Python 3.11 or later. Create a Rime API key and setRIME_API_KEY in your server’s environment.
Create a project and install the transport client and message definitions:
rime-api supplies generated Protobuf classes and schema files. Your application still uses a standard WebSocket client to connect, authenticate, send messages, and manage retries. The LiveKit plugin uses these same message classes.
Stream audio to a file
Save this asstream_binary.py. It overwrites output.pcm in the current directory. Decode each server message as WebSocketResponse, then read its audio field. The full WebSocket message includes Protobuf metadata and cannot go directly to a player.
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.
Empty Protobuf messages still need presence. Call request.end.SetInParent() or request.cancel.SetInParent() to select these payloads. Constructing a request with only a context_id sends no operation.
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.
Generate bindings for another language
The installed package includesschema/rime/text_to_speech.proto and schema/text_to_speech.asyncapi.yaml. Use the Protobuf source to generate messages for your language. The AsyncAPI file describes the JSON encoding.
This command copies the installed Protobuf schema to your project:
rime.WebSocketRequest and rime.WebSocketResponse with your language’s Protobuf compiler. Each WebSocket message carries one serialized message. Do not add a gRPC header, length prefix, base64 layer, or custom framing. The schema defines gRPC services too, but this WebSocket client only needs the message types.
Use the Coda WebSocket API reference for message fields, connection reuse, cancellation, and errors.
