Text-to-Speech
Transformers
Safetensors
tts
vits
mms
indic
english
hindi
marathi
TTS / README.md
Sudhanshu619's picture
Add banner and architecture diagram; move app screenshot to Demo section
e56c2b0 verified
|
Raw History Blame Contribute Delete
16.9 kB
---
license: cc-by-nc-4.0
language:
- multilingual
- en
- hi
- mr
pipeline_tag: text-to-speech
library_name: transformers
tags:
- text-to-speech
- tts
- vits
- mms
- multilingual
- indic
- english
- hindi
- marathi
base_model:
- facebook/mms-tts-eng
- facebook/mms-tts-hin
- facebook/mms-tts-mar
---
<div align="center">
# SDLC Corp · Multilingual Text-to-Speech
**Lightweight, end-to-end speech synthesis for 1,100+ languages, with English, Hindi and Marathi bundled and ready to use**
[![License: CC BY-NC 4.0](https://img.shields.io/badge/License-CC%20BY--NC%204.0-lightgrey.svg)](https://creativecommons.org/licenses/by-nc/4.0/)
[![Task: Text-to-Speech](https://img.shields.io/badge/Task-Text--to--Speech-blue.svg)](#quick-start)
[![Languages: 1,100+](https://img.shields.io/badge/Languages-1%2C100%2B-green.svg)](#languages)
[![Bundled: EN | HI | MR](https://img.shields.io/badge/Bundled-EN%20%7C%20HI%20%7C%20MR-teal.svg)](#bundled-languages)
[![Transformers](https://img.shields.io/badge/%F0%9F%A4%97%20Transformers-VITS-orange.svg)](https://huggingface.co/docs/transformers/model_doc/vits)
[![Audio](https://img.shields.io/badge/Audio-16%20kHz%20mono-purple.svg)](#technical-specifications)
</div>
![SDLC Corp Multilingual Text-to-Speech: 1,100+ languages through one interface](assets/banner.png)
## Overview
**SDLC Corp Multilingual TTS** turns text into natural speech in **more than 1,100 languages**
through one consistent 🤗 Transformers interface. It is built on Meta AI's
[Massively Multilingual Speech (MMS)](https://arxiv.org/abs/2305.13516) text-to-speech models,
which use the VITS architecture.
Language support works on two levels:
| | Languages | Loaded from | What you change |
|---|---|---|---|
| **Bundled** | English, Hindi, Marathi | `SDLC-Corp/TTS` (this repository) | `subfolder="eng"`, `"hin"` or `"mar"` |
| **Extended** | 1,100+ others, such as Bengali, Tamil, Telugu, Spanish, French and Arabic | `facebook/mms-tts-<code>` (Meta) | The model ID |
The code, API and output format are the same for every language. The
[`MultilingualTTS` class](#one-interface-for-every-language) below handles both levels
automatically, so you pass a language name and get audio back.
![How it works: input text and language go through MultilingualTTS, which loads a bundled or extended VITS checkpoint, producing 16 kHz speech](assets/architecture.png)
### Highlights
- **1,100+ languages, one interface.** Bundled and extended languages share the same API.
- **End to end.** Text goes in and a 16 kHz waveform comes out, with no separate vocoder or
phonemizer.
- **Lightweight.** About 36M parameters and 145 MB per language, fast enough for a CPU.
- **Native scripts.** Devanagari, Bengali, Tamil, Arabic and many other scripts are taken
directly. A small number of languages need romanization, which is
[handled for you](#romanized-languages).
- **Load on demand.** Each language downloads only once, on first use, and is cached locally.
## Table of Contents
1. [Languages](#languages)
2. [Quick Start](#quick-start)
3. [Usage](#usage)
4. [Generation Controls](#generation-controls)
5. [Performance and Hardware](#performance-and-hardware)
6. [Technical Specifications](#technical-specifications)
7. [Intended Use](#intended-use)
8. [Limitations](#limitations)
9. [Ethical Considerations](#ethical-considerations)
10. [Demo Application](#demo-application)
11. [License](#license)
12. [Citation](#citation)
## Languages
### Bundled languages
Stored in this repository and loaded with `subfolder=`:
| Language | Code | Script | Vocabulary | Source checkpoint |
|---|---|---|---|---|
| English | `eng` | Latin (lowercased automatically) | 38 symbols | [facebook/mms-tts-eng](https://huggingface.co/facebook/mms-tts-eng) |
| Hindi (हिन्दी) | `hin` | Devanagari | 72 symbols | [facebook/mms-tts-hin](https://huggingface.co/facebook/mms-tts-hin) |
| Marathi (मराठी) | `mar` | Devanagari | 73 symbols | [facebook/mms-tts-mar](https://huggingface.co/facebook/mms-tts-mar) |
```
SDLC-Corp/TTS
├── eng/ ─┐
├── hin/ ├─ config.json · model.safetensors · tokenizer_config.json
├── mar/ ─┘ special_tokens_map.json · vocab.json
├── assets/
└── README.md
```
Only the requested subfolder is downloaded, so loading Hindi does not fetch English or Marathi.
### Extended languages (1,100+)
Every other language uses Meta's checkpoint `facebook/mms-tts-<code>`, where `<code>` is the
[ISO 639-3](https://iso639-3.sil.org/code_tables/639/data) language code. Some languages have
script variants, such as `urd-script_arabic`. Commonly used examples:
| Region | Languages (code) |
|---|---|
| India and South Asia | Bengali (`ben`) · Tamil (`tam`) · Telugu (`tel`) · Gujarati (`guj`) · Kannada (`kan`) · Malayalam (`mal`) · Punjabi (`pan`) · Odia (`ory`) · Assamese (`asm`) · Urdu (`urd-script_arabic`, `urd-script_devanagari`, `urd-script_latin`) |
| Europe | Spanish (`spa`) · French (`fra`) · German (`deu`) · Portuguese (`por`) · Russian (`rus`) |
| Middle East and Africa | Arabic (`ara`) · Swahili (`swh`) · Yoruba (`yor`) |
| East and Southeast Asia | Indonesian (`ind`) · Vietnamese (`vie`) · Thai (`tha`) · Korean (`kor`, romanized) |
**Find your language:** browse all checkpoints on the
[Hugging Face Hub](https://huggingface.co/models?search=facebook/mms-tts) or in
[Meta's language coverage list](https://dl.fbaipublicfiles.com/mms/misc/language_coverage_mms.html).
### Romanized languages
A few checkpoints, such as Korean, were trained on romanized text. Their tokenizer reports
`is_uroman = True`, and input must first be converted to Latin script with
[uroman](https://github.com/isi-nlp/uroman) (`pip install uroman`). The
[`MultilingualTTS` class](#one-interface-for-every-language) does this automatically.
### Coverage notes
- Coverage is broad but not universal. For example, Mandarin Chinese and Japanese have no
MMS-TTS checkpoint.
- Quality varies by language with the amount of training data. Evaluate a language on your
own content before relying on it.
## Quick Start
**Requirements:** Python 3.10+
```bash
pip install torch transformers soundfile
```
**A bundled language** (English, Hindi or Marathi):
```python
import torch
import soundfile as sf
from transformers import AutoTokenizer, VitsModel
repo, lang = "SDLC-Corp/TTS", "hin" # "eng", "hin" or "mar"
tokenizer = AutoTokenizer.from_pretrained(repo, subfolder=lang)
model = VitsModel.from_pretrained(repo, subfolder=lang).eval()
inputs = tokenizer("नमस्ते, आप कैसे हैं?", return_tensors="pt")
torch.manual_seed(0) # generation is stochastic; fix the seed for reproducible audio
with torch.inference_mode():
waveform = model(**inputs).waveform[0].numpy()
sf.write("output.wav", waveform, model.config.sampling_rate) # 16 kHz WAV
```
**Any other language.** Use Meta's model ID and drop `subfolder`:
```python
model_id = "facebook/mms-tts-tam" # Tamil
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = VitsModel.from_pretrained(model_id).eval()
inputs = tokenizer("வணக்கம், எப்படி இருக்கிறீர்கள்?", return_tensors="pt")
torch.manual_seed(0)
with torch.inference_mode():
waveform = model(**inputs).waveform[0].numpy()
sf.write("tamil.wav", waveform, model.config.sampling_rate)
```
## Usage
### One interface for every language
`MultilingualTTS` takes a language name or code. It loads bundled languages from this
repository and all others from Meta, romanizes input where required, caches loaded models,
and uses a GPU when one is available.
```python
import torch
from transformers import AutoTokenizer, VitsModel
class MultilingualTTS:
REPO = "SDLC-Corp/TTS"
BUNDLED = {"eng", "hin", "mar"}
ALIASES = {
"english": "eng", "hindi": "hin", "marathi": "mar",
"bengali": "ben", "tamil": "tam", "telugu": "tel", "gujarati": "guj",
"kannada": "kan", "malayalam": "mal", "punjabi": "pan", "odia": "ory",
"spanish": "spa", "french": "fra", "german": "deu", "arabic": "ara",
}
def __init__(self, device: str | None = None):
self.device = device or ("cuda" if torch.cuda.is_available() else "cpu")
self._models: dict[str, tuple] = {}
def _load(self, code: str):
if code not in self._models:
if code in self.BUNDLED:
repo, kwargs = self.REPO, {"subfolder": code}
else:
repo, kwargs = f"facebook/mms-tts-{code}", {}
tokenizer = AutoTokenizer.from_pretrained(repo, **kwargs)
model = VitsModel.from_pretrained(repo, **kwargs).to(self.device).eval()
self._models[code] = (tokenizer, model)
return self._models[code]
@torch.inference_mode()
def synthesize(self, text: str, language: str, seed: int = 0):
"""Return (waveform as float32 numpy array, sample_rate)."""
code = self.ALIASES.get(language.lower(), language)
tokenizer, model = self._load(code)
if getattr(tokenizer, "is_uroman", False):
import uroman # pip install uroman
text = uroman.Uroman().romanize_string(text)
inputs = tokenizer(text, return_tensors="pt").to(self.device)
if inputs["input_ids"].shape[-1] == 0:
raise ValueError(f"Text contains no characters supported by the '{code}' model.")
torch.manual_seed(seed)
waveform = model(**inputs).waveform[0].cpu().numpy()
return waveform, model.config.sampling_rate
tts = MultilingualTTS()
audio, sr = tts.synthesize("नमस्कार, आपले स्वागत आहे.", "marathi") # bundled
audio, sr = tts.synthesize("নমস্কার, আপনি কেমন আছেন?", "bengali") # extended
audio, sr = tts.synthesize("Hola, ¿cómo estás?", "spa") # any ISO 639-3 code
```
### With the `text-to-speech` pipeline
```python
import soundfile as sf
from transformers import AutoTokenizer, VitsModel, pipeline
repo, lang = "SDLC-Corp/TTS", "eng"
tts_pipe = pipeline(
"text-to-speech",
model=VitsModel.from_pretrained(repo, subfolder=lang),
tokenizer=AutoTokenizer.from_pretrained(repo, subfolder=lang),
)
result = tts_pipe("Welcome to SDLC Corp.")
sf.write("welcome.wav", result["audio"].squeeze(), result["sampling_rate"])
```
For an extended language, pass `pipeline("text-to-speech", model="facebook/mms-tts-<code>")`.
### Playback in a notebook
```python
from IPython.display import Audio
Audio(audio, rate=sr)
```
## Generation Controls
These attributes can be adjusted on any loaded model before generation:
| Attribute | Default | Description |
|---|---|---|
| `model.speaking_rate` | `1.0` | Speech tempo. Values above `1.0` are faster, below are slower. |
| `model.noise_scale` | `0.667` | Prosodic variation. Lower values give flatter, more consistent intonation. |
| `model.noise_scale_duration` | `0.8` | Variation in phoneme timing. |
```python
model.speaking_rate = 0.9 # slightly slower delivery
model.noise_scale = 0.5 # steadier intonation
```
VITS sampling is stochastic. Call `torch.manual_seed(...)` before each generation when you
need deterministic output.
## Performance and Hardware
| | CPU | GPU |
|---|---|---|
| Supported | Yes, out of the box | Yes, any CUDA-capable GPU |
| Memory per loaded language | ~150 MB RAM | < 1 GB VRAM |
| Typical latency (short sentence) | A few seconds on a laptop CPU | Well under a second |
| Download per language | ~145 MB, once | ~145 MB, once |
Every language uses the same architecture, so these figures apply to all of them. A free
Google Colab or Kaggle T4 GPU is more than sufficient.
## Technical Specifications
| Property | Value |
|---|---|
| Architecture | [VITS](https://arxiv.org/abs/2106.06103): conditional VAE with adversarial training, normalizing-flow prior and stochastic duration predictor |
| Text encoder | 6 transformer layers · hidden size 192 · 2 attention heads · FFN 768 |
| Waveform decoder | HiFi-GAN-style generator, upsampling ×8 · ×8 · ×2 · ×2 |
| Parameters | ~36M per language |
| Weights format | `safetensors`, float32 |
| Tokenizer | `VitsTokenizer`, character-level; uroman romanization for a small set of languages |
| Speakers | Single speaker per language |
| Output | 16 kHz · mono · float32 waveform |
| Language coverage | 3 bundled (eng, hin, mar) · 1,100+ via MMS-TTS checkpoints |
| Training data | MMS read-speech recordings (predominantly religious texts), per Pratap et al. (2023) |
| Original developer | Meta AI |
| Packaged by | [SDLC Corp](https://huggingface.co/SDLC-Corp) |
## Intended Use
**Suitable for**
- Multilingual products and research, especially for Indian and low-resource languages
- Accessibility tools such as screen readers and read-aloud features
- Education, language-learning material, internal demos and proofs of concept
- Lightweight on-device or CPU-only deployments
**Out of scope**
- Commercial products or services (prohibited by the license)
- Voice cloning, speaker impersonation or expressive/emotional speech
- Languages without an MMS-TTS checkpoint (for example Mandarin Chinese and Japanese)
## Limitations
- **Script must match the model.** Each model expects its own script (for example Devanagari
for Hindi, Tamil script for Tamil). Unsupported characters are dropped by the tokenizer,
which can result in empty input. The `MultilingualTTS` class checks for this.
- **No text normalization.** Digits, dates, currency and abbreviations are not expanded.
Spell them out (for example "twenty-five" or "पच्चीस") for correct pronunciation.
- **One language per model.** Segment mixed-language text (for example Hinglish) and route
each segment to the matching language.
- **Single voice.** One neutral voice per language, with no speaker or style selection.
- **Uneven quality.** Naturalness varies across languages with the amount of training data.
- **Domain shift.** Training data is predominantly read religious text, so conversational or
technical content may sound less natural.
## Ethical Considerations
Synthetic speech can be misused. Do not use these models to impersonate real individuals,
to produce deceptive or fraudulent audio, or to present generated speech as a genuine
recording. Where generated audio is published, we recommend disclosing that it is synthetic.
## Demo Application
A Gradio web application for the bundled languages is available on GitHub. It offers
language tabs, a character counter, an audio player, WAV download and automatic CPU/GPU
detection.
![Demo application: language tabs, text input, audio player and WAV download](assets/demo.png)
```bash
git clone https://github.com/Sudhanshu619/TTS.git
cd TTS
pip install torch --index-url https://download.pytorch.org/whl/cpu # or a CUDA build
pip install -r requirements-demo.txt
python app.py # http://127.0.0.1:7860
```
## License
All MMS-TTS model weights, both those bundled here and Meta's extended-language checkpoints,
are developed by **Meta AI** and distributed under the
**[Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)](https://creativecommons.org/licenses/by-nc/4.0/)**
license.
- **Non-commercial use only.** The models, and audio generated with them, may not be used
for commercial purposes.
- **Attribution.** Credit Meta AI and the MMS authors, and reference the license.
- **Modifications.** The English, Hindi and Marathi checkpoints are consolidated into one
repository, and only their `safetensors` weights are distributed. Model weights are
unchanged. Extended languages are loaded directly from Meta's repositories.
## Citation
If you use these models in your work, please cite the original MMS paper:
```bibtex
@article{pratap2023mms,
title = {Scaling Speech Technology to 1,000+ Languages},
author = {Vineel Pratap and Andros Tjandra and Bowen Shi and Paden Tomasello and Arun Babu
and Sayani Kundu and Ali Elkahky and Zhaoheng Ni and Apoorv Vyas and Maryam Fazel-Zarandi
and Alexei Baevski and Yossi Adi and Xiaohui Zhang and Wei-Ning Hsu and Alexis Conneau
and Michael Auli},
journal = {arXiv preprint arXiv:2305.13516},
year = {2023}
}
```
## Acknowledgements
- [Meta AI, Massively Multilingual Speech](https://github.com/facebookresearch/fairseq/tree/main/examples/mms):
original models and research
- [🤗 Hugging Face Transformers](https://github.com/huggingface/transformers): VITS implementation and inference
- [Gradio](https://www.gradio.app/): demo application UI
<div align="center">
Maintained by **[SDLC Corp](https://huggingface.co/SDLC-Corp)**
</div>