Skip to main content
Both calls return streaming audio. Install the SDK from the SDK overview. This page lists the methods, options, defaults, and errors. For walkthroughs and complete programs, see the SDK guides and examples.

Stream incremental text

stream takes a source of text fragments, and it returns audio chunks while the service makes them. By default, the audio is raw PCM16, little-endian, mono, at 24 kHz. Pass each fragment when it arrives. The SDK asks the service to collect the fragments into complete sentences before synthesis, so you do not need to split the text yourself. Text flows from your application through the backend Rime SDK to Rime TTS. Streaming audio returns through the SDK to your player or transport. Each example below reads text from your source and passes every audio chunk to send_audio, which stands for your player or transport. client is an open client. Options by language gives the source types.

Synthesize complete text

synthesize takes one complete, nonblank string. It returns the same kind of audio stream as stream, and it does not buffer the entire audio response. Read the audio stream the same way.

Guides and examples

The Rime SDK repository keeps the TTS guide and runnable examples for each language next to the SDK source.

Models and audio

Coda is the default model. The SDK also supports Mist v3. Both models use the language en, unless you set a different language. The SDK sends your API key as a bearer token over TLS. Set RIME_API_KEY, or give an explicit API key. The SDK does not load .env files. A custom endpoint takes a hostname and an optional port. Do not include a scheme or a path. The default port is 443. PCM and mu-law chunks have no file header. Each chunk contains complete sample frames, but the chunk sizes vary. Send the chunks to your player, or add a header to save a WAV file. The current releases also offer WAV and MP3 output. Those chunks are fragments of one file. For a complete WAV file, select WAV output and call the buffer helper:

Completion and errors

A stream can return audio before it fails. Treat the output as complete only after the stream ends successfully. The SDK does not retry synthesis automatically. Overall timeouts include pauses between reads. If you disable the overall timeout, the internal connection and progress limits stay active. Discovery allows at most 10 seconds, and if you supply a shorter deadline, the shorter deadline applies. Python and TypeScript errors inherit from RimeError. In Go, use errors.Is for categories and errors.As for request details. In Rust, error.kind() gives the category. Keep the request ID when you report a failure.

Options by language

The Python package has installation steps and examples.stream accepts an async iterable of strings. Do not await the method call. Work starts when you enter the async context of the stream or read the first chunk.

Client options

Select Mist v3 with Rime(model="mistv3").For a custom deployment, set endpoint="host:8443".

Synthesis options

Use stream(source, ...) for an async iterable of strings. Use synthesize(text, ...) for a nonblank string. Both accept the same optional keyword arguments:

Audio formats

Use AudioFormat.PCM_24000 for PCM or AudioFormat.MULAW_8000 for mu-law. Read format metadata from audio.format.encoding, audio.format.sample_rate, and audio.format.channels.

Discover voices and languages

These calls list the English voices and all languages for Mist v3, which is the model of the client:
Both calls return lists of strings and accept timeout. Omit language to disable filtering.

Errors and cancellation

Every SDK error is a RimeError subclass from the table in Completion and errors. Import the classes from rimelabs_sdk, and read the request ID from error.request_id. The Python TTS guide shows how to catch the error around the entry point of your application.Use the async with block of the stream, because the SDK cancels unfinished work when the block exits. A cancelled Python task raises asyncio.CancelledError. You can also stop work yourself: await audio.cancel() stops one operation, and await client.close() stops all client work. You can safely repeat both calls. A client belongs to one process and one event loop.
The current methods separate complete text from incremental input:
  • In Python and TypeScript, stream no longer accepts a string.
  • Go no longer provides StreamSource.
  • In Rust, synthesis is under client.tts().