ToneXLabs is a complete, end-to-end AI voice generation platform that replaces external, paid APIs (like ElevenLabs) with a self-hosted, fine-tunable, and scalable solution. This project manages everything from AI model fine-tuning to API deployment and a full-stack user-facing application.
The primary goal is to achieve full ownership of the AI stack, enabling deep customization (like fine-tuning specific voices) and removing dependency on third-party services.
- Text-to-Speech (TTS): Utilizes a fine-tuned
StyleTTS2model to generate high-quality speech from text in a specific voice. - Voice Conversion (VC): Employs a
seed-vcmodel to transform an input audio file into a different target voice. - Text-to-Sound Effects (SFX): Leverages a
make-an-audiomodel to generate sound effects from a text prompt. - Self-Hosted & Scalable: The entire AI backend is containerized with Docker and deployed on AWS EC2, complete with a job queue to manage high-load.
- Deep Customization: Includes a complete workflow for fine-tuning models on a GPU instance and saving the custom "brains" to S3.
This project is a full-stack solution, separating the AI backend, cloud infrastructure, and frontend.
| Component | Technology |
|---|---|
| Frontend | Next.js, React, TypeScript, Tailwind CSS |
| Backend | Python, FastAPI, PyTorch, Docker, Docker Compose |
| AI Models | StyleTTS2, seed-vc, make-an-audio |
| Cloud (AWS) | EC2 (g5.xlarge GPU Instance), S3 (Object Storage), ECR (Container Registry), IAM (Roles & Policies) |
| Job Queue | Inngest (to prevent server overload) |
The system is split into a Next.js Frontend (likely hosted on Vercel) and a Python Backend running on a single, powerful AWS EC2 instance.
The core backend runs on a G5.xlarge EC2 instance, managed by docker-compose. It orchestrates three separate API containers, each serving a specific AI model:
styletts2-api: Listens on Port8000for Text-to-Speech requests.seed-vc-api: Listens on Port8001for Voice Conversion requests.make-a-sound-api: Listens on Port8002for Text-to-SFX requests.
The EC2 instance's Security Group is configured to allow public TCP traffic on ports 8000, 8001, and 8002 so the Next.js frontend can communicate with each service.
- Frontend: User enters text, selects a voice, and hits "Generate."
- HTTP Request: The Next.js app sends an HTTP request to
http://<EC2_IP>:8000/generate. - Backend: The
styletts2-api(FastAPI) receives the request, runs the AI model, and generates a.wavfile. - Backend -> S3: The backend uploads the generated audio file to an
styletts2-outputsS3 bucket. - HTTP Response: The API returns a JSON response to the frontend containing the S3 URL of the new file.
- Frontend: The app's audio player plays the audio directly from the S3 URL.
#### Voice Conversion (VC) Flow
- Frontend: User uploads an audio file (e.g.,
my_voice.wav), selects a target voice, and hits "Generate." The frontend uploads this file directly to anseedvc-audio-uploadsS3 bucket. - HTTP Request: The Next.js app sends an HTTP request to
http://<EC2_IP>:8001/convert, passing the S3 URL of the newly uploaded file. - Backend: The
seed-vc-apidownloads the user's audio from S3. - Backend: The
seed-vcmodel runs, converting the audio to the target voice. - Backend -> S3: The backend uploads the newly generated audio file to an
seedvc-outputsS3 bucket. - HTTP Response: The API returns the S3 URL of the converted file.
- Frontend: The app's audio player plays the new audio from the S3 link.
#### Text-to-SFX Flow
This flow is identical to the TTS flow, but it uses the
make-an-audio model on port 8002.
This is a one-off job performed to create the custom, fine-tuned model files used by the deployment server.
- StyleTTS2: Requires 10-15 minutes of high-quality, segmented audio (1-10s clips) and a corresponding
.srttranscription file. - seed-vc: Uses the same 10-15 minutes of audio, but only needs the raw audio files (no transcription required).
- Local Machine: The
Dockerfile, dataset, and model code are "baked" into a "training" Docker image (e.g.,styletts2-ft). - Upload to ECR: This image is pushed to a private AWS ECR repository.
- Launch EC2: A powerful
G5.xlargeinstance is manually started, using a "Deep Learning PyTorch AMI" to ensure all NVIDIA drivers are pre-installed. - Pull & Run: The user SSH's into the instance, pulls the image from ECR, and starts the Docker container to begin training.
- Upload Model: After training, the container uploads the new model file (e.g.,
finetuned_model.pth) to an AWS S3 bucket (e.g.,styletts2-models). - Terminate: The EC2 instance is terminated to stop all costs.
The "Deployment" server is then configured to download and use this new .pth file from S3.
Permissions are handled using a standard, secure IAM setup:
- IAM User (
styletts2-api): A long-term user with an access key and secret. It is only used on a local machine for administrative tasks like uploading data to S3 from a local script. - IAM Role (
tonexlabs-ec2): A temporary, more secure set of permissions attached directly to the EC2 instance. The application on the server automatically "assumes" this role. This role grants the EC2 instance the necessary permissions to:ecr:Pullimages from ECR.s3:PutObjectands3:GetObjectto read and write audio files from the S3 buckets.
This avoids the insecure practice of hard-coding secret access keys inside the deployed application.
- An AWS account with quota for a
g5.xlargeinstance. - AWS CLI configured on your local machine.
- Docker & Docker Compose.
- Node.js &
npm/yarn. - Python 3.10+.
You will need to set up your environment variables.
Frontend (/frontend):
Create a .env.local file:
NEXT_PUBLIC_TTS_API_URL=http://<YOUR_EC2_IP>:8000
NEXT_PUBLIC_VC_API_URL=http://<YOUR_EC2_IP>:8001
NEXT_PUBLIC_SFX_API_URL=http://<YOUR_EC2_IP>:8002
# Auth.js Config
AUTH_SECRET=...
GITHUB_ID=...
GITHUB_SECRET=...
Backend (/backend):
Create a .env file for the Docker Compose environment:
# AWS Credentials for the server to access S3/ECR
# (Note: Best practice is an IAM Role, but keys can be used)
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
AWS_REGION=ap-south-1
# S3 Bucket Names
TTS_OUTPUT_BUCKET=tonexlabs-styletts2-outputs
VC_UPLOAD_BUCKET=tonexlabs-seedvc-uploads
VC_OUTPUT_BUCKET=tonexlabs-seedvc-outputs
cd frontend
npm install
npm run devcd backend
pip install -r requirements.txt
# Run a single service (e.g., TTS)
uvicorn main_tts:app --host 0.0.0.0 --port 8000-
Build & Push Images:
# From the /backend directory docker compose build docker compose push -
Run on EC2:
- SSH into your configured EC2 instance.
- Make sure Docker and Docker Compose are installed.
- Create the
.envfile on the server. - Run
docker compose pullto get your images from ECR. - Run
docker compose up -dto start the services in the background.