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
1# Import SarvamAI client and save helper
2from sarvamai import SarvamAI
3from sarvamai.play import save
1# Initialize the SarvamAI client with your API key
2client = SarvamAI(api_subscription_key="YOUR_API_SUBSCRIPTION_KEY")
1# Example 1: Without text preprocessing (default)
2audio = client.text_to_speech.convert(
3 text="The price is Rs. 1,00,000 on 25th December, 2024",
4 target_language_code="en-IN",
5 enable_preprocessing=False
6)
1#Example 2: With text preprocessing enabled
2audio = client.text_to_speech.convert(
3 text="The price is Rs. 1,00,000 on 25th December, 2024",
4 model="bulbul:v2",
5 target_language_code="en-IN",
6 enable_preprocessing=True # Enable smart text normalization
7)
1# Save the generated audio to a file
2save(audio, "output_pitch_up.wav")