> For clean Markdown of any page, append `.md` to the page URL.
> For a complete documentation index, see https://docs.sarvam.ai/llms.txt.
> For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server.

# How to adjust the pitch (tone)

> Control the tone of the synthesized speech (bulbul:v2 only).

**Important:** The `pitch` parameter is only supported for **bulbul:v2**. It is not available for bulbul:v3.

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.

### Example Code

```python
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 (pitch is only supported in bulbul:v2)
audio = client.text_to_speech.convert(
    text="Welcome to Sarvam AI!",
    model="bulbul:v2",
    target_language_code="en-IN",
    speaker="anushka",
    pitch=0.5  # Increase pitch for a sharper tone
)
save(audio, "output1.wav")

```

```python
import asyncio
import base64
from sarvamai import AsyncSarvamAI, AudioOutput
import websockets

async def tts_stream():
    client = AsyncSarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")

    # Note: pitch is only supported for bulbul:v2
    async with client.text_to_speech_streaming.connect(model="bulbul:v2") as ws:
        await ws.configure(
            target_language_code="hi-IN", 
            speaker="anushka",
            pitch=0.5  # Increase pitch for a sharper tone
        )
        print("Sent configuration")

        text = (
            "भारत की संस्कृति विश्व की सबसे प्राचीन और समृद्ध संस्कृतियों में से एक है।"
            "यह विविधता, सहिष्णुता और परंपराओं का अद्भुत संगम है, "
            "जिसमें विभिन्न धर्म, भाषाएं, त्योहार, संगीत, नृत्य, वास्तुकला और जीवनशैली शामिल हैं।"
        )

        await ws.convert(text)
        print("Sent text message")

        await ws.flush()
        print("Flushed buffer")

        chunk_count = 0
        with open("output.mp3", "wb") as f:
            async for message in ws:
                if isinstance(message, AudioOutput):
                    chunk_count += 1
                    audio_chunk = base64.b64decode(message.data.audio)
                    f.write(audio_chunk)
                    f.flush()

        print(f"All {chunk_count} chunks saved to output.mp3")
        print("Audio generation complete")

        
        if hasattr(ws, "_websocket") and not ws._websocket.closed:
            await ws._websocket.close()
            print("WebSocket connection closed.")


if __name__ == "__main__":
    asyncio.run(tts_stream())

# --- Notebook/Colab usage ---
# await tts_stream()

```