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.
Metadata
Release files for sarvam-tts 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sarvam_tts-1.1.tar.gz | 18.0 kB | Without provenance | Details for sarvam_tts-1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sarvam_tts-1.1-py3-none-any.whl | Python 3 | none | any | Details for sarvam_tts-1.1-py3-none-any.whl |
Total release size: 35.0 kB
Release files / sarvam_tts-1.1.tar.gz
| Download URL | sarvam_tts-1.1.tar.gz |
|---|---|
| Size | 18.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e485be3c475d7f5d147392a694930135e9e7b3d129561e46daf889852c3fb7bd
|
|
BLAKE2b-256 checksum How to use checksums |
1269bd88c88767b95b232b763154aac0c0c77a5bf290680867aab411ebb2b30d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Release files / sarvam_tts-1.1-py3-none-any.whl
| Download URL | sarvam_tts-1.1-py3-none-any.whl |
|---|---|
| Size | 17.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef1002379fbcbbe4ec836778f779cd1950132b65696aa238a1e9adb00e68fd85
|
|
BLAKE2b-256 checksum How to use checksums |
23b4079fea8d19865895dd73293920bfb0f9d52dfcfd946cc4be0cbfd5986bd9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.0
|
Security for sarvam-tts 1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.