DEV Community

VoiceDeveloper
VoiceDeveloper

Posted on

Deploy a Voice Cloning Demo App: From Code to Live Website

Why Voice Cloning Is the Next Big Thing

If you’ve ever wanted a personal narrator that sounds exactly like you (or a celebrity), you’re not alone. Voice‑cloning tech has gone from a research curiosity to a production‑ready capability in just a few years. With APIs that turn a few seconds of reference audio into a high‑fidelity synthetic voice, you can embed custom speech into podcasts, e‑learning platforms, or even interactive chatbots.

In this article we’ll walk through building a tiny demo app that:

  1. Takes a text string from a web form.
  2. Sends it to the ElevenLabs voice‑cloning API.
  3. Streams the generated audio back to the browser.

Then we’ll push the app live on Bluehost, the affordable hosting provider that makes deployment a breeze for developers of any skill level.


What You’ll Need

Item Why it matters
ElevenLabs API key Powers the text‑to‑speech (TTS) and voice‑cloning engine. Grab yours at the ElevenLabs signup page.
Python 3.9+ We’ll use Flask for the web server.
Git To push the code to Bluehost’s Git deployment (or you can upload via FTP).
A Bluehost account Provides a cheap, one‑click way to host the app. Sign up with the link below.
A small reference audio file (15‑30 seconds) Used by ElevenLabs to create a custom voice model.

Step 1: Get an ElevenLabs API Key

Head over to the ElevenLabs developer portal, sign up, and copy the secret key from the dashboard. Keep it safe – you’ll need it in the .env file later.

ELEVENLABS_API_KEY=your_secret_key_here
Enter fullscreen mode Exit fullscreen mode

Pro tip: ElevenLabs offers a free tier that gives you a few thousand characters per month – perfect for a demo.


Step 2: Scaffold a Minimal Flask App

Create a new folder and set up a virtual environment:

mkdir voice-clone-demo && cd voice-clone-demo
python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate
pip install Flask python-dotenv requests
Enter fullscreen mode Exit fullscreen mode

app.py

import os
from flask import Flask, render_template, request, jsonify
import requests
from dotenv import load_dotenv

load_dotenv()
API_KEY = os.getenv("ELEVENLABS_API_KEY")
VOICE_ID = "YOUR_VOICE_ID"   # will be created in Step 3

app = Flask(__name__)

@app.route("/")
def index():
    return render_template("index.html")

@app.route("/speak", methods=["POST"])
def speak():
    text = request.json.get("text", "")
    if not text:
        return jsonify({"error": "No text provided"}), 400

    url = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}"
    headers = {
        "xi-api-key": API_KEY,
        "Content-Type": "application/json"
    }
    payload = {
        "text": text,
        "voice_settings": {
            "stability": 0.75,
            "similarity_boost": 0.85
        }
    }

    resp = requests.post(url, json=payload, headers=headers, stream=True)
    if resp.status_code != 200:
        return jsonify({"error": resp.text}), resp.status_code

    # Return raw audio bytes (mp3) to the client
    return resp.content, 200, {"Content-Type": "audio/mpeg"}

if __name__ == "__main__":
    app.run(debug=True)
Enter fullscreen mode Exit fullscreen mode

templates/index.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Voice Clone Demo</title>
</head>
<body>
  <h1>🗣️ Try Your Custom Voice</h1>
  <textarea id="text" rows="4" cols="50" placeholder="Enter text here..."></textarea><br>
  <button id="speakBtn">Speak</button>
  <audio id="player" controls></audio>

  <script>
    document.getElementById('speakBtn').onclick = async () => {
      const text = document.getElementById('text').value;
      const resp = await fetch('/speak', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({ text })
      });
      if (resp.ok) {
        const blob = await resp.blob();
        const url = URL.createObjectURL(blob);
        const player = document.getElementById('player');
        player.src = url;
        player.play();
      } else {
        alert('Error: ' + await resp.text());
      }
    };
  </script>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

Step 3: Create a Custom Voice on ElevenLabs

ElevenLabs lets you upload a short reference clip and instantly generate a voice ID.

curl -X POST "https://api.elevenlabs.io/v1/voices/add" \
  -H "xi-api-key: $ELEVENLABS_API_KEY" \
  -H "Content-Type: multipart/form-data" \
  -F "name=MyDemoVoice" \
  -F "files=@/path/to/your/reference.wav"
Enter fullscreen mode Exit fullscreen mode

The response contains a voice_id. Replace YOUR_VOICE_ID in app.py with that value.

Note: If you’re just testing, you can skip this step and use one of ElevenLabs’ public voices (e.g., EXAVITQu4vr4xnSDxMaL). The URL would be .../text-to-speech/EXAVITQu4vr4xnSDxMaL.


Step 4: Test Locally

Run the Flask server:

flask run
Enter fullscreen mode Exit fullscreen mode

Open http://127.0.0.1:5000 in your browser, type a sentence, hit Speak, and you should hear the cloned voice. If everything works, you’re ready to go live.


Step 5: Deploy to Bluehost �� The Easy, Affordable Way

Bluehost offers a one‑click Python app setup on shared hosting plans. Here’s how to get the demo up in under ten minutes.

5.1. Spin Up a Bluehost Account

If you don’t already have one, sign up via the affiliate link: Bluehost – affordable hosting for developers. The basic plan includes enough CPU and storage for a low‑traffic demo, and you’ll get cPanel access for free.

5.2. Prepare Your Repo

Create a Git repo in the project folder:

git init
git add .
git commit -m "Initial commit"
Enter fullscreen mode Exit fullscreen mode

Push it to a remote (GitHub, GitLab, or Bitbucket). Bluehost can pull from any public repo, or you can use their Git™ Version Control tool to clone directly.

5.3. Set Up the Python App in cPanel

  1. Log into Bluehost’s cPanel.
  2. Under Software → Setup Python App, click Create Application.
  3. Choose Python 3.9, set the Application Root (e.g., voice-clone-demo), and give it a Domain/Subdomain (e.g., demo.yourdomain.com).
  4. Click Create – cPanel will provision a virtual environment and give you a WSGI file path.

5.4. Install Dependencies

In the Terminal (or via SSH) run:

source /home/username/virtualenvs/voice-clone-demo/3.9/bin/activate
pip install Flask python-dotenv requests
Enter fullscreen mode Exit fullscreen mode

Alternatively, you can place a requirements.txt in the repo and let cPanel install it automatically:

Flask
python-dotenv
requests
Enter fullscreen mode Exit fullscreen mode

5.5. Deploy Your Code

In cPanel’s Git™ Version Control section:

  • Click Create and paste the URL of your repo.
  • Choose the same Application Root you set earlier.
  • Click Create – Bluehost will clone the repo and run a post‑checkout script.

If you prefer manual upload, just zip the project and use File Manager to extract it into the app directory.

5.6. Wire Up the WSGI Entry Point

Edit the auto‑generated WSGI file (e.g., passenger_wsgi.py) to point to your Flask app:

import sys
sys.path.insert(0, '/home/username/voice-clone-demo')

from app import app as application
Enter fullscreen mode Exit fullscreen mode

Save and Restart the app from cPanel. Your demo should now be reachable at https://demo.yourdomain.com.


Step 6: Secure Your API Key

Never commit the .env file to the repo. In Bluehost’s cPanel, go to Software → Environment Variables and add ELEVENLABS_API_KEY with the value you copied earlier. Flask will read it automatically via python-dotenv.


Bonus: Adding a Simple Rate Limiter

If you expect public traffic, protect your ElevenLabs quota with a tiny limiter:

from flask import abort
from time import time

last_call = 0
MIN_INTERVAL = 1.5  # seconds between calls

@app.route("/speak", methods=["POST"])
def speak():
    global last_call
    if time() - last_call < MIN_INTERVAL:
        abort(429, description="Too many requests – please wait a moment.")
    last_call = time()
    # …rest of the function unchanged…
Enter fullscreen mode Exit fullscreen mode

What You’ve Built

  • A front‑end form that captures user text.
  • A Flask back‑end that talks to the ElevenLabs voice‑cloning API.
  • A live, publicly accessible URL hosted on Bluehost, handling HTTPS and scaling automatically for modest traffic.

All of this took under an hour and cost less than a cup of coffee per month on the Bluehost shared plan.


Next Steps

  • Add authentication (OAuth, API keys) if you want to restrict usage.
  • Cache generated audio on a CDN (Cloudflare, BunnyCDN) to reduce API calls.
  • Experiment with different voice settings – stability vs. similarity boost – to find the sweet spot for your use case.

Ready to Play with Voice AI?

The combination of ElevenLabs’s high‑quality voice‑cloning API and Bluehost’s straightforward hosting makes it possible for anyone to spin up a voice‑enabled web app in minutes. Grab your ElevenLabs API key at the official site: try ElevenLabs now, and if you need a reliable, budget‑friendly host, give Bluehost a try.

Happy coding, and may your projects sound as good as they look!

Top comments (0)