quantumphysicistsam/SpeechGeneration
0
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
TTS with Voice Cloning – UI & API
This repository provides a text-to-speech (TTS) application built with Coqui TTS’s voice cloning model. It offers both:
- A Web UI: Built with Gradio for interactive synthesis.
- An API: Built with FastAPI for programmatic access.
If no speaker reference file is provided, the application will use your default recorded voice (my_voice.wav) for voice cloning.
Features
- Voice Cloning TTS: Synthesize speech using Coqui TTS’s multilingual voice cloning model.
- Multiple Language Support: (Supported languages:
en,fr-fr,pt-br) - Web UI: Interactively enter text, choose language, and optionally upload a speaker reference.
- API Endpoint: POST requests to synthesize speech from your applications.
- Deployment Ready: Easily deployable to Hugging Face Spaces via your GitHub repository.
Files in This Repository
- app.py Contains the FastAPI application with:
- An API endpoint at
/api/synthesize/ - A mounted Gradio UI at
/ui - requirements.txt Lists the required Python packages.
- my_voice.wav Your recorded voice file (used as the default speaker reference if no file is uploaded).
How It Works
API Endpoint
- URL:
/api/synthesize/ - Method:
POST - Form Data Parameters:
text(string, required): The text to synthesize.language(string, required): The language code (e.g.,en,fr-fr, orpt-br).speaker_file(file, optional): A WAV file of a speaker reference. If not provided, the defaultmy_voice.wavwill be used if available.
- Response: Returns the synthesized speech as a WAV file.
Web UI
- URL:
/ui - Use the interactive Gradio interface to enter text, select language, and (optionally) upload a speaker file. Click the button to synthesize and play back the audio.
Running Locally
- Clone the repository:
git clone https://github.com/<your-username>/<your-repo-name>.git
cd <your-repo-name>
2. **Install Dependencies**
pip install -r requirements.txt
- Run the application
uvicorn app:app --host 0.0.0.0 --port 8000
4. **Access the UI and API**
UI: Open your browser and navigate to http://localhost:8000/ui API: The API endpoint is available at http://localhost:8000/api/synthesize/
- Sample Python Client for the API Below is a sample Python script that demonstrates how to call the TTS API endpoint using the "requests" library:
import requests
# Replace with your deployed Hugging Face Spaces URL (or localhost for testing)
API_URL = "http://localhost:8000/api/synthesize/"
# Prepare the form data
data = {
"text": "Hello, this is a test of the TTS API.",
"language": "en"
}
# (Optional) Include a speaker reference file if you want:
# files = {"speaker_file": open("path/to/your/speaker.wav", "rb")}
files = {} # No file provided; the default my_voice.wav will be used
response = requests.post(API_URL, data=data, files=files)
if response.status_code == 200:
# Save the returned WAV file
with open("output.wav", "wb") as f:
f.write(response.content)
print("Synthesized audio saved as output.wav")
else:
print("Error:", response.json())