Skip to navigation

Adjust the pitch

View as Markdown

The pitch parameter shifts the voice lower (negative values) or higher (positive values). 0.0 leaves the voice unchanged.

ParameterTypeRangeDefaultModelsAPIs
pitchnumber-0.5–0.50.0bulbul:v4-flash, bulbul:v3REST, HTTP stream, WebSocket

Example

import os
from sarvamai import SarvamAI
from sarvamai.play import save
client = SarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
response = client.text_to_speech.convert(
text="Welcome to Sarvam AI!",
language_code="en-IN",
model="bulbul:v4-flash",
speaker="simran_en_customer",
pitch=0.3,
)
save(response, "output.wav")

pitch is set in the configure message and applies to every convert call that follows. The Python SDK names the language argument target_language_code; it is sent as language_code.

import asyncio
import base64
import os
from sarvamai import AsyncSarvamAI, AudioOutput
async def main():
client = AsyncSarvamAI(api_subscription_key=os.environ["SARVAM_API_KEY"])
async with client.text_to_speech_streaming.connect(model="bulbul:v4-flash") as ws:
await ws.configure(
target_language_code="en-IN",
speaker="simran_en_customer",
pitch=0.3, # sharper than normal
)
await ws.convert("Welcome to Sarvam AI!")
await ws.flush()
with open("output.mp3", "wb") as f:
async for message in ws:
if isinstance(message, AudioOutput):
f.write(base64.b64decode(message.data.audio))
asyncio.run(main())

What changes in the output

Negative values make the voice deeper and positive values make it sharper.

Start with small shifts and listen before moving toward the limits. Keep the same pitch across a conversation so the voice stays consistent. Choosing a different speaker is usually a better way to get a very different voice.

Common errors

Out-of-range values are rejected with HTTP 400 on REST. On WebSocket, the error arrives as a JSON message with code 422 or 400 instead.

RequestError
pitch below -0.5 or above 0.5For the Bulbul V3 and V4 models, pitch should be between -0.5 and 0.5

On WebSocket, send a new configure message to change pitch mid-session. Text still in the buffer is flushed first, then the new settings apply.