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
SarvamTTSAPI for generating MP3 output - Configurable
TTSConfigfor 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__.pyexports the public API:SarvamTTS,TTSConfig,TTSException, andTTSRequestErrorsarvam_tts/config.pycontains supported languages, default API URL, and configuration validationsarvam_tts/providers/sarvam.pyimplements the Sarvam AI request flow and audio saving logicsarvam_tts/providers/base.pydefines the provider abstractionsarvam_tts/utils.pycontains the multilingual sentence tokenizerexample.pydemonstrates 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
englishhindibengalitamiltelugukannadamalayalammarathigujaratipunjabiodia
🎤 Example Voice Names
The library supports common voice names such as:
shreyashubhmananishitapriyasuhaniashutoshrituamitsumitpoojasimranrahulkavyaratanshrutiadityasohamrehanvijaytarunanandaayanrohandevsunnykabirvarunnehamanimohitrupaliadvaitroopatanyagokulkavitha
🔧 API Reference
SarvamTTS.tts(...)
Parameters:
text– text to synthesizelanguage– optional override for the languagevoice– optional override for the voicepace– optional override for speaking pacetemperature– optional override for voice variabilitysample_rate– optional override for sample rateoutput_filepath– optional output path
TTSConfig
The configuration object provides defaults for:
timeoutverboseoutput_pathlanguagevoicepacetemperaturesample_rateapi_url
🖼️ How It Works
SarvamTTSaccepts text and configuration values.- The text is split into sentence-level chunks.
- Each chunk is sent to the Sarvam AI endpoint concurrently.
- Audio responses are merged into a single MP3 payload.
- 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:
- Fork the repository
- Create a feature branch
- Commit your changes
- Open a pull request
📄 License
This project is licensed under the MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sarvam_tts-1.0.tar.gz.
File metadata
- Download URL: sarvam_tts-1.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58a45be45cc2292ddcc03feb29ed209249e188ec1a84a341488a781298b05518
|
|
| MD5 |
33838a3abb9d924c1a402a0294e60456
|
|
| BLAKE2b-256 |
47ab1cbc3da6e0a3b8323c4e668a46175585f1cc2c4679345d4343723abc1d6c
|
File details
Details for the file sarvam_tts-1.0-py3-none-any.whl.
File metadata
- Download URL: sarvam_tts-1.0-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c027988dd5cdaf9cf6eee07dde212e9bf4fc792cc7ba8f3a23ce3af4beecb1b1
|
|
| MD5 |
7526359a2ad0744765b8976052deeccb
|
|
| BLAKE2b-256 |
2bae56e0204d11718f6d16179310a576245a1678058497714c3aa66f37fc900e
|