Skip to navigation

Enable text preprocessing

View as Markdown

enable_preprocessing normalises the input text before synthesis, so numbers, dates, currencies and mixed-language text are read the way a person would say them.

Parameterenable_preprocessing
Typeboolean
Defaultfalse
APIsREST, HTTP streaming, WebSocket (config message)
Modelsbulbul:v3, bulbul:v4-flash

Preprocessing is off unless you set it to true. It is accepted on both current models and changes the generated audio.

Example

import os
from sarvamai import SarvamAI
from sarvamai.play import save
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
response = client.text_to_speech.convert(
text="Pay Rs. 1,00,000 by 25/12/2024.",
language_code="en-IN",
model="bulbul:v3",
speaker="shubh",
enable_preprocessing=True,
)
save(response, "output.wav")

For HTTP streaming, send the same field to /text-to-speech/stream. For WebSocket, add "enable_preprocessing": true to the config message (or enable_preprocessing=True in the Python SDK’s ws.configure(...)). See WebSocket TTS.

What changes in the output

  • Text such as amounts, dates and abbreviations is normalised before it is spoken. Compare the two outputs for your own content to judge the difference.
  • The audio differs from the same request with preprocessing off. Set temperature to 0.01 when you compare, so the only difference is the setting.
  • Leave it off if you already write numbers and dates out in words, or if you want the text spoken exactly as given.

Common errors

This parameter has no error of its own in testing. A non-boolean string such as "yes" was accepted with a 200 response, so send a real boolean.

Unknown request fields are ignored without an error, so a misspelled parameter name silently has no effect. If preprocessing seems to do nothing, check the spelling.