Skip to main content
The text-to-speech API supports text rewriting rules that normalize and expand certain patterns in the input text before synthesis. These rules help the TTS model properly pronounce numbers, currency amounts, email addresses, URLs, and alphanumeric codes.

Configuration

Rewrite rules are controlled by the rewrite_rules field of json_config. Its value is a single string: either a language or locale code (e.g. "en"), or "none" to disable rewriting. json_config goes in the setup message for WebSocket sessions, or in the request body for the REST endpoint:

Default behavior

For both the production and beta models, when the selected voice has a language associated with it, the API enables that language’s rules by default. So a session using an English voice behaves as if you had passed "rewrite_rules": "en". Setting rewrite_rules yourself overrides this default.

Disabling rewriting: none

Pass "rewrite_rules": "none" to turn all rewrite rules off. Because of the language default described above, this is the only way to get unrewritten text for a voice that has a language: omitting the field enables the voice language’s rules, while "none" disables them.
With rules disabled, only minimal text normalization is applied before synthesis.

Supported Languages and Locales

Each value enables the full set of rewriting rules for that language or locale: Belgian and Swiss French share most of their rewriting with metropolitan French; the differences are in how dates, numbers and currency amounts are spoken, so pick fr-be or fr-ch when your audience is in those markets.

What Gets Rewritten

With a language or locale selected, the following are expanded into the spoken form of that language:
  • Numbers, including negative values and large magnitudes
  • Currency amounts, with the symbol before or after the amount
  • Email addresses
  • URLs
  • Alphanumeric codes and identifiers, such as reference or product codes
  • Dashed digit sequences, such as phone and account numbers
Years and small numbers are kept as written, and punctuation around a rewritten pattern is preserved.

Custom Rewrites: Pronunciation Dictionaries

Rewrite rules handle general patterns (numbers, currency amounts, emails, URLs). To rewrite specific words or phrases of your own (brand names, acronyms, domain jargon), use a pronunciation dictionary instead. The dictionary is not part of rewrite_rules or json_config: create it in the Gradium Studio (or via the pronunciations API) and pass its ID as pronunciation_id at the top level of the setup message, next to voice_id:
Dictionary entries are applied to the text first, then the pattern rules run on the result. The two combine freely. For example, a dictionary that expands your product’s acronym, plus "en" rules to read out prices and product codes. Pronunciation dictionaries apply to WebSocket sessions only; REST requests cannot use them, and only the pattern-based rewrite_rules are available there.

Best Practices

  1. Match the value to the voice - use the language or locale of the voice you synthesise with, and rely on the default when they already match
  2. Use the locale codes - fr-be and fr-ch read dates, numbers and amounts the way those markets expect
  3. Disable deliberately - pass "none" when your text is already written the way it should be spoken