How to adjust the pitch (tone)

The pitch parameter controls the tone of the synthesized speech by making the voice deeper or sharper.

It is optional, and if omitted, the default value 0.0 (neutral pitch) is used.

  • Range: -0.75 (deeper voice) to 0.75 (sharper voice)
  • Default: 0.0 (neutral pitch)

Use this to make the voice sound either lower or higher depending on your preference or use case.

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 pitch (neutral tone)
2audio = client.text_to_speech.convert(
3 text="Welcome to Sarvam AI!",
4 model="bulbul:v2",
5 target_language_code="en-IN",
6 pitch=0.0 #neutral pitch
7)
1#Example2: Using selected pitch (sharper tone)
2audio = client.text_to_speech.convert(
3 text="Hello, how are you today?",
4 model="bulbul:v2",
5 target_language_code="en-IN",
6 pitch=0.5 # Increase pitch for a sharper tone
7)
1# Save the generated audio to a file
2save(audio, "output_pitch_up.wav")