Klonr - Voice Cloning Studio

AI-powered voice cloning and text-to-speech platform built with Spark-TTS-0.5B. Clone any voice from a short audio sample, then generate natural-sounding speech in that voice.

Features

  • Voice Cloning - Clone a voice from a single audio sample (MP3, WAV, M4A, OGG, FLAC)
  • Text-to-Speech - Generate speech with cloned or built-in voices
  • Batch Synthesis - Bulk generate audio from CSV files (up to 100 sentences)
  • Streaming Audio - Real-time audio streaming for low-latency playback
  • Google OAuth - Sign in with Google or email/password
  • Dashboard - Real-time usage stats, activity feed, and weekly usage chart
  • REST API - Full API with interactive Swagger docs at /docs

Tech Stack

Layer Technology
TTS Model Spark-TTS-0.5B (PyTorch)
Backend FastAPI, SQLAlchemy, SQLite
Frontend React 19, Tailwind CSS, Framer Motion
Auth JWT + Google OAuth 2.0

Project Structure

klonr/
├── main.py                  # FastAPI app entrypoint
├── config.py                # App settings (env vars)
├── database.py              # SQLAlchemy setup
├── requirements.txt         # Python dependencies
├── Makefile                 # Setup & run commands
├── .env                     # Environment variables (create this)
├── models/
│   ├── db_models.py         # User, Voice, TTSHistory tables
│   └── schemas.py           # Pydantic request/response models
├── routers/
│   ├── auth.py              # Auth endpoints (login, register, Google OAuth)
│   ├── voices.py            # Voice CRUD + cloning endpoints
│   └── tts.py               # TTS synthesis, streaming, batch, stats
├── services/
│   ├── auth_service.py      # JWT, password hashing, user management
│   └── tts_service.py       # Spark TTS model loading & inference
├── pretrained_models/
│   └── Spark-TTS-0.5B/      # TTS model weights (~3.7GB)
├── spark_tts/               # Spark TTS source code
├── frontend/
│   ├── src/
│   │   ├── App.jsx
│   │   ├── context/AuthContext.jsx
│   │   ├── hooks/useVoices.js
│   │   └── components/
│   │       ├── Dashboard.jsx
│   │       ├── Synthesize.jsx
│   │       ├── BatchSynthesize.jsx
│   │       ├── Clone.jsx
│   │       ├── Voices.jsx
│   │       ├── Settings.jsx
│   │       ├── ApiDocs.jsx
│   │       ├── AuthModal.jsx
│   │       └── ui/           # Reusable UI components
│   └── public/
├── uploads/                  # Cloned voice audio samples
└── audio_output/             # Generated audio files

Quick Start

Prerequisites

  • Python 3.10+
  • Node.js 18+
  • Git LFS (for downloading the model)
  • NVIDIA GPU recommended (runs on CPU but very slow)

1. Clone and setup

git clone https://github.com/YOUR_USERNAME/voice-cloning.git
cd voice-cloning

# Full setup: venv + dependencies + model download + frontend
make setup

Or step by step:

# Create virtual environment
make setup-venv
source venv/bin/activate

# Install Python dependencies
make install-deps

# Download Spark TTS model (~3.7GB)
make download-model

# Clone Spark TTS source code
make clone-spark-code

# Install frontend dependencies
make setup-frontend

2. Configure environment

Create a .env file in the project root:

# JWT Authentication
JWT_SECRET_KEY="your-secret-key-change-this"
JWT_ALGORITHM="HS256"
JWT_EXPIRATION_HOURS=24

# Google OAuth (optional - get from Google Cloud Console)
GOOGLE_CLIENT_ID=""
GOOGLE_CLIENT_SECRET=""
GOOGLE_REDIRECT_URI="http://localhost:8000/auth/google/callback"

# Frontend URL
FRONTEND_URL="http://localhost:3000"

3. Run

# Run both backend and frontend
make run

# Or run separately:
make run-backend    # FastAPI on http://localhost:8000
make run-frontend   # React on http://localhost:3000
make dev            # Backend with hot reload

4. Open the app

API Endpoints

Authentication

Method Endpoint Description
POST /auth/register Register with email/password
POST /auth/login Login with email/password
GET /auth/google Google OAuth login
GET /auth/google/callback Google OAuth callback
GET /auth/verify Verify JWT token

Voices

Method Endpoint Description
GET /voices List all voices
GET /voices/{voice_id} Get voice details
POST /voices/register Register a new voice
POST /voices/clone Clone a voice from audio
PUT /voices/{voice_id} Update voice metadata
DELETE /voices/{voice_id} Delete a voice

Text-to-Speech

Method Endpoint Description
POST /tts/synthesize Generate speech (returns file ID)
POST /tts/synthesize/stream Stream audio in real-time
GET /tts/audio/{file_id} Download generated audio
GET /tts/history Get synthesis history
GET /tts/stats Get usage statistics
POST /tts/batch Batch synthesis from CSV

Synthesis Request Example

curl -X POST http://localhost:8000/tts/synthesize \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Hello, welcome to Klonr!",
    "voice_id": "cloned_abc123_myvoice",
    "speaking_rate": 1.0,
    "temperature": 1.1,
    "audio_format": "MP3"
  }'

Batch CSV Format

text,voice_id,speaking_rate
"Hello, this is sentence one.",,1.0
"This is sentence two.",,1.0

GPU vs CPU

GPU (NVIDIA T4+) CPU
Speed per sentence 2-5 seconds 1-5 minutes
Batch of 10 ~30 seconds 10-50 minutes
Recommended for Production Testing only

Check GPU availability:

make check-gpu

Deployment

Google Cloud (recommended for free credits)

  1. Frontend - Deploy to Firebase Hosting (free)
  2. Backend + TTS - GCE n1-standard-4 with NVIDIA T4 spot instance (~$0.22/hr)
  3. Use auto-shutdown scripts to stop the VM when idle

Google Cloud offers $300 free credits for new accounts (~1,300 hours of GPU).

Other Options

Platform GPU Cost Notes
Google Cloud ~$0.22/hr (spot T4) $300 free credits
RunPod Serverless ~$0.00025/sec Pay per second
Vast.ai ~$0.07-0.15/hr Cheapest raw GPU
Modal.com Free tier available Serverless GPU

Makefile Commands

make help             # Show all commands
make setup            # Complete setup
make run              # Run backend + frontend
make dev              # Backend with hot reload
make check-gpu        # Check CUDA/GPU status
make info             # Show project info and paths
make clean            # Remove __pycache__ files
make clean-audio      # Remove generated audio
make clean-db         # Remove database (destructive)

Database

SQLite database (voice_cloning.db) with three tables:

  • users - Email/password and Google OAuth accounts
  • voices - Built-in and cloned voice configurations
  • tts_history - All synthesis records with audio file paths

The database is auto-created on first run.

License

This project uses Spark-TTS-0.5B by SparkAudio. Refer to the model's license for usage terms.

Built With

Share this project:

Updates