Skip to main content

A Python client for Sarvam AI text-to-speech that supports multilingual Indian language synthesis.

Project description

Sarvam TTS

sarvam-tts is a Python client for the Sarvam AI text-to-speech API. It provides a clean SarvamTTS interface for multilingual Indian language synthesis, configurable output settings, and chunked request handling for reliable audio generation.

⚠️ This project is provided for educational and research purposes only. Please comply with Sarvam AI's terms of service and acceptable use policies when using the API.

✨ Features

  • Multi-language TTS support for Indian languages
  • Simple SarvamTTS API for generating MP3 output
  • Configurable TTSConfig for language, voice, pace, temperature, sample rate, and timeout
  • Concurrent chunk generation for long texts
  • Package metadata and install support via setup.py

📁 Project Structure

sarvam-tts/
├── README.md
├── LICENSE
├── requirements.txt
├── setup.py
├── example.py
├── sarvam_tts/
│   ├── __init__.py
│   ├── config.py
│   ├── exceptions.py
│   ├── utils.py
│   └── providers/
│       ├── __init__.py
│       ├── base.py
└───────└── sarvam.py

Package contents

  • sarvam_tts/__init__.py exports the public API: SarvamTTS, TTSConfig, TTSException, and TTSRequestError
  • sarvam_tts/config.py contains supported languages, default API URL, and configuration validation
  • sarvam_tts/providers/sarvam.py implements the Sarvam AI request flow and audio saving logic
  • sarvam_tts/providers/base.py defines the provider abstraction
  • sarvam_tts/utils.py contains the multilingual sentence tokenizer
  • example.py demonstrates basic usage

🛠️ Installation

Using PyPI (Recommended)

pip install sarvam-tts

Clone Locally

git clone https://github.com/sujalrajpoot/sarvam-tts.git
cd sarvam-tts
pip install -r requirements.txt

🧪 Quick Start

from sarvam_tts import SarvamTTS

client = SarvamTTS()

output_path = client.tts(
    text="Hello from Sarvam TTS!",
    language="english",
    voice="shreya",
    pace=1.0,
    temperature=0.6,
    sample_rate=22050,
    output_filepath="output.mp3",
)

print(output_path)

You can also customize the configuration directly:

from sarvam_tts import TTSConfig, SarvamTTS

config = TTSConfig(
    language="hindi",
    voice="shreya",
    pace=1.0,
    temperature=0.4,
    sample_rate=22050,
    output_path="demo/output.mp3",
)

client = SarvamTTS(config=config)
client.tts("नमस्ते, यह एक उदाहरण है।")

🧠 Supported Languages

  • english
  • hindi
  • bengali
  • tamil
  • telugu
  • kannada
  • malayalam
  • marathi
  • gujarati
  • punjabi
  • odia

🎤 Example Voice Names

The library supports common voice names such as:

  • shreya
  • shubh
  • manan
  • ishita
  • priya
  • suhani
  • ashutosh
  • ritu
  • amit
  • sumit
  • pooja
  • simran
  • rahul
  • kavya
  • ratan
  • shruti
  • aditya
  • soham
  • rehan
  • vijay
  • tarun
  • anand
  • aayan
  • rohan
  • dev
  • sunny
  • kabir
  • varun
  • neha
  • mani
  • mohit
  • rupali
  • advait
  • roopa
  • tanya
  • gokul
  • kavitha

🔧 API Reference

SarvamTTS.tts(...)

Parameters:

  • text – text to synthesize
  • language – optional override for the language
  • voice – optional override for the voice
  • pace – optional override for speaking pace
  • temperature – optional override for voice variability
  • sample_rate – optional override for sample rate
  • output_filepath – optional output path

TTSConfig

The configuration object provides defaults for:

  • timeout
  • verbose
  • output_path
  • language
  • voice
  • pace
  • temperature
  • sample_rate
  • api_url

🖼️ How It Works

  1. SarvamTTS accepts text and configuration values.
  2. The text is split into sentence-level chunks.
  3. Each chunk is sent to the Sarvam AI endpoint concurrently.
  4. Audio responses are merged into a single MP3 payload.
  5. The final audio is saved to the requested output path.

🧪 Running the Example

python example.py

The script generates sample audio files in a Test/ directory.

🤝 Contributing

Contributions are welcome. To contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Open a pull request

📄 License

This project is licensed under the MIT License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sarvam_tts-1.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sarvam_tts-1.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file sarvam_tts-1.1.tar.gz.

File metadata

  • Download URL: sarvam_tts-1.1.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for sarvam_tts-1.1.tar.gz
Algorithm Hash digest
SHA256 e485be3c475d7f5d147392a694930135e9e7b3d129561e46daf889852c3fb7bd
MD5 92358f1334a08bbc00dd9ab25e2fc414
BLAKE2b-256 1269bd88c88767b95b232b763154aac0c0c77a5bf290680867aab411ebb2b30d

See more details on using hashes here.

File details

Details for the file sarvam_tts-1.1-py3-none-any.whl.

File metadata

  • Download URL: sarvam_tts-1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for sarvam_tts-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef1002379fbcbbe4ec836778f779cd1950132b65696aa238a1e9adb00e68fd85
MD5 a4dcb3481b449e5a573ec5dc4807a269
BLAKE2b-256 23b4079fea8d19865895dd73293920bfb0f9d52dfcfd946cc4be0cbfd5986bd9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page