How to enable text preprocessing

The enable_preprocessing parameter improves pronunciation of numbers, dates, currencies, and mixed-language text.

It is optional — if omitted, default is False (no preprocessing).

When enabled:

  • Numbers are expanded (e.g., "Rs. 1,00,000" → “rupees one lakh”)
  • Dates are read naturally (e.g., “25th December, 2024” → “twenty-fifth December two thousand twenty-four”)
  • Abbreviations and symbols are handled correctly

Example Code

1from sarvamai import SarvamAI
2from sarvamai.play import save
3
4# Initialize the REST client
5client = SarvamAI(api_subscription_key="YOUR_API_SUBSCRIPTION_KEY")
6
7# Generate speech using REST
8audio = client.text_to_speech.convert(
9 text="Welcome to Sarvam AI!",
10 model="bulbul:v2",
11 target_language_code="en-IN",
12 enable_preprocessing=True # Enable smart text normalization
13)
14save(audio, "output1.wav")