How to enable text preprocessing

View as Markdown

Important: The enable_preprocessing parameter is only supported for bulbul:v2. It is not available for bulbul:v3.

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

from sarvamai import SarvamAI
from sarvamai.play import save
# Initialize the REST client
client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")
# Generate speech using REST (bulbul:v2 only)
audio = client.text_to_speech.convert(
text="Welcome to Sarvam AI!",
model="bulbul:v2",
language_code="en-IN",
speaker="anushka",
enable_preprocessing=True # Enable smart text normalization
)
save(audio, "output1.wav")