How to adjust the loudness (volume)

The loudness parameter controls the volume level of the generated audio.

It is optional — if omitted, the default value 1.0 (normal loudness) is used.

  • Valid range: 0.1 (quietest) to 3.0 (loudest)
  • Values < 1.0 reduce volume; values > 1.0 increase volume.
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# Example1: Using default loudness (normal volume)
2audio = client.text_to_speech.convert(
3 text="Welcome to Sarvam AI!",
4 model="bulbul:v2",
5 target_language_code="en-IN",
6 loudness=1.0
7)
1#Example2: Using selected loudness (higher volume)
2audio = client.text_to_speech.convert(
3 text="Hello, how are you today?",
4 model="bulbul:v2",
5 target_language_code="en-IN",
6 loudness=2.0 # Increase loudness for a louder output
7)
1# Save the generated audio to a file
2save(audio, "output_pitch_up.wav")