ebitlogix/Parler_TTS_API
0
1---2title: Parler TTS API3emoji: 🎙️4colorFrom: blue5colorTo: green6sdk: docker7app_file: api.py8python_version: 3.109---10 11# Indic Parler-TTS API12 13FastAPI endpoint for Urdu Text-to-Speech using [ai4bharat/indic-parler-tts](https://huggingface.co/ai4bharat/indic-parler-tts).14 15## API Endpoints16 17### Health Check18```19GET /20```21Returns model status and available speakers.22 23**Response:**24```json25{26 "status": "ok",27 "model": "Indic Parler-TTS",28 "speakers": ["Divya", "Rani", "Rohit", "Aman", "Generic Female", "Generic Male"],29 "sample_rate": 2400030}31```32 33### Generate Speech34```35POST /tts36```37 38**Request Body:**39```json40{41 "text": "السلام علیکم، میرا نام اردو ٹی ٹی ایس ہے۔",42 "speaker": "Divya",43 "pitch": "Moderate",44 "rate": "Moderate",45 "temperature": 0.8,46 "do_sample": true47}48```49 50**Parameters:**51- `text` (string, required): Urdu text to synthesize52- `speaker` (string, optional): Speaker name. Options: `Divya`, `Rani`, `Rohit`, `Aman`, `Generic Female`, `Generic Male`. Default: `Divya`53- `pitch` (string, optional): Voice pitch. Options: `High`, `Moderate`, `Low`. Default: `Moderate`54- `rate` (string, optional): Speaking rate. Options: `Slow`, `Moderate`, `Fast`. Default: `Moderate`55- `temperature` (float, optional): Sampling temperature (0.1-2.0). Default: `0.8`56- `do_sample` (boolean, optional): Use sampling vs greedy decoding. Default: `true`57 58**Response:**59- WAV audio file (audio/wav)60 61### Get Available Speakers62```63GET /speakers64```65 66**Response:**67```json68{69 "speakers": ["Divya", "Rani", "Rohit", "Aman", "Generic Female", "Generic Male"]70}71```72 73## Example Usage74 75### cURL76```bash77curl -X POST http://localhost:7860/tts \78 -H "Content-Type: application/json" \79 -d '{80 "text": "السلام علیکم",81 "speaker": "Divya",82 "pitch": "Moderate",83 "rate": "Moderate"84 }' \85 --output speech.wav86```87 88### Python89```python90import requests91import json92 93url = "http://localhost:7860/tts"94payload = {95 "text": "السلام علیکم، میرا نام اردو ٹی ٹی ایس ہے۔",96 "speaker": "Divya",97 "pitch": "Moderate",98 "rate": "Moderate",99 "temperature": 0.8,100 "do_sample": True101}102 103response = requests.post(url, json=payload)104if response.status_code == 200:105 with open("speech.wav", "wb") as f:106 f.write(response.content)107 print("Audio saved!")108else:109 print(f"Error: {response.status_code}")110 print(response.text)111```112 113## Running Locally114 115### With Docker116```bash117docker build -t parler-tts-api .118docker run -p 7860:7860 --gpus all parler-tts-api119```120 121### Without Docker122```bash123python3 -m venv venv124source venv/bin/activate125pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121126pip install -r requirements.txt127pip install uvicorn[standard]128python api.py129```130 131Then visit `http://localhost:7860/docs` for interactive API documentation.132 133## Environment Variables134 135For HF Spaces deployment, set the following secret:136- `HF_TOKEN`: Your Hugging Face API token (required for gated model access)137 138## Technical Details139 140- **Model**: Indic Parler-TTS (multi-speaker, multi-language)141- **Language**: Urdu (auto-detected from script)142- **Sample Rate**: 24 kHz143- **Audio Format**: WAV (16-bit PCM)144- **Framework**: FastAPI + PyTorch145- **Deployment**: HF Spaces Docker runtime146 147### Quality Notes148- Language is auto-detected from Urdu script — do NOT mention language in voice descriptions149- Named speakers (Divya, Rohit, etc.) provide consistent voices150- Same random seed used across sentences for voice consistency within a generation151- Text cleaning removes Latin/English characters to prevent language mixing152 