Overview
Voice cloning has moved from “science‑fiction” to a practical tool you can spin up in an afternoon. In this guide we’ll walk through a complete mini‑project: a web app that lets you type any text, pick a cloned voice, and hear the result instantly. We’ll use ElevenLabs for the text‑to‑speech (TTS) engine, a tiny Flask backend to talk to the API, and Bluehost as the cheap, hassle‑free host that will get your demo online with a single click.
By the end of this post you’ll have:
- A Python script that records a short voice sample and creates a clone with ElevenLabs.
- A Flask API that receives text, calls the clone, and streams back an MP3.
- A minimal HTML/JS front‑end to interact with the API.
- A live, publicly accessible site hosted on Bluehost.
Let’s dive in!
1. Setting Up the ElevenLabs Account
First, sign up for an ElevenLabs account (the free tier already gives you 10 k characters per month). Use the affiliate link so we both get a little boost: try ElevenLabs here.
Once you’re logged in, grab your API key:
- Click Profile → API Keys.
- Hit Create new key and copy the string – you’ll need it in the next step.
Keep the key secret; treat it like a password.
2. Recording a Sample & Creating a Clone
ElevenLabs requires a short voice sample (≈ 30 seconds) to generate a clone. For this demo we’ll use a local WAV file, but any microphone recording will do.
# Install the ElevenLabs Python client
pip install elevenlabs
# clone_creator.py
import os
from elevenlabs import Voice, save_voice
API_KEY = os.getenv("ELEVENLABS_API_KEY") # set this in your .env
# Path to your 30‑second voice sample (mono, 16 kHz preferred)
sample_path = "my_voice_sample.wav"
# Create the voice clone
voice = Voice.create(
name="my_clone",
description="A clone of my own voice",
files=[sample_path],
api_key=API_KEY,
)
# Save the voice ID for later use
save_voice(voice, "voice_id.txt")
print(f"Clone created! Voice ID: {voice.voice_id}")
Run the script once you have my_voice_sample.wav ready:
ELEVENLABS_API_KEY=your_api_key_here python clone_creator.py
The script stores the new voice’s ID in voice_id.txt. Keep that ID handy – it’s what you’ll pass to the TTS endpoint.
3. Building the Flask Backend
Now we’ll expose a tiny API that accepts a POST request with text and returns the generated audio.
pip install flask requests python-dotenv
# app.py
import os
import base64
from flask import Flask, request, jsonify, send_file
import requests
from dotenv import load_dotenv
load_dotenv()
API_KEY = os.getenv("ELEVENLABS_API_KEY")
VOICE_ID = os.getenv("ELEVENLABS_VOICE_ID") # put the ID from clone_creator
app = Flask(__name__)
ELEVENLABS_TTS_URL = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}"
@app.route("/synthesize", methods=["POST"])
def synthesize():
data = request.get_json()
text = data.get("text", "")
if not text:
return jsonify({"error": "No text supplied"}), 400
payload = {
"text": text,
"voice_settings": {"stability": 0.75, "similarity_boost": 0.85},
}
headers = {
"xi-api-key": API_KEY,
"Content-Type": "application/json",
}
resp = requests.post(ELEVENLABS_TTS_URL, json=payload, headers=headers, stream=True)
if resp.status_code != 200:
return jsonify({"error": "ElevenLabs API error", "details": resp.text}), 500
# Save the audio temporarily
audio_path = "output.mp3"
with open(audio_path, "wb") as f:
for chunk in resp.iter_content(chunk_size=8192):
f.write(chunk)
return send_file(audio_path, mimetype="audio/mpeg")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
Create a .env file in the project root:
ELEVENLABS_API_KEY=your_api_key_here
ELEVENLABS_VOICE_ID=the_voice_id_from_step_2
Run locally to test:
python app.py
Then in another terminal:
curl -X POST http://127.0.0.1:5000/synthesize \
-H "Content-Type: application/json" \
-d '{"text":"Hello, this is my cloned voice speaking from Flask!"}' \
--output demo.mp3
Open demo.mp3 – you should hear your own voice saying the text.
4. Front‑End: A One‑Page Demo
Create an index.html file in a static folder (Flask will serve it automatically).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Voice Clone Demo</title>
<style>
body { font-family: Arial, sans-serif; margin: 2rem; }
textarea { width: 100%; height: 80px; }
button { padding: 0.5rem 1rem; margin-top: 0.5rem; }
</style>
</head>
<body>
<h1>Try My Voice Clone</h1>
<textarea id="txt" placeholder="Type something..."></textarea><br>
<button id="speak">Speak</button>
<audio id="player" controls style="display:none;"></audio>
<script>
const btn = document.getElementById('speak');
const txt = document.getElementById('txt');
const player = document.getElementById('player');
btn.addEventListener('click', async () => {
const response = await fetch('/synthesize', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: txt.value })
});
if (!response.ok) {
alert('Error: ' + (await response.text()));
return;
}
const blob = await response.blob();
const url = URL.createObjectURL(blob);
player.src = url;
player.style.display = 'block';
player.play();
});
</script>
</body>
</html>
Update app.py to serve static files:
@app.route("/")
def home():
return app.send_static_file("index.html")
Now visiting http://localhost:5000/ shows a tiny UI where you can type text and hear the cloned voice instantly.
5. Deploying with Bluehost
When it comes to getting a Flask app online, many developers wrestle with Docker, VPS setup, or serverless quirks. Bluehost removes that friction. With their one‑click Python app support, you can push the same repo you just built and have it running behind a secure HTTPS endpoint in minutes.
Why Bluehost?
- Affordability – Plans start under $5/month, perfect for a demo or a low‑traffic hobby project.
- Ease of use – Their control panel includes a built‑in Git deployment tool, so you don’t have to manage Nginx or uWSGI yourself.
- Free SSL – Your voice clone API will be served over HTTPS automatically, which is required for most browsers to play audio.
Sign up using this link: Bluehost – the easy, affordable way to host your voice AI project.
Deployment Steps
- Create a new “Python App” in the Bluehost dashboard. Choose Python 3.11 (or the latest available).
- Connect your Git repo – you can push the code to a private GitHub repository and then link it in the “Deploy” section.
-
Set environment variables – add
ELEVENLABS_API_KEYandELEVENLABS_VOICE_IDunder “Environment”. -
Install dependencies – Bluehost provides a terminal. Run
pip install -r requirements.txt. -
Specify the entry point – set the startup command to
python app.py. -
Hit “Deploy” – the platform builds the virtualenv, starts the Flask server, and maps it to a subdomain like
yourproject.bluehost.com.
That’s it. In under ten minutes you have a publicly reachable voice cloning demo.
6. Going Live & Next Steps
Now that the site is live, you can:
- Add authentication (e.g., a simple API key header) to stop strangers from draining your ElevenLabs quota.
- Cache audio – store generated MP3s in a CDN or on the Bluehost storage to reduce repeated TTS calls.
- Expand the UI – let users upload their own samples, choose from multiple clones, or tweak voice settings in real time.
Remember to monitor your ElevenLabs usage. The free tier is generous, but a public endpoint can be abused if left open.
TL;DR
- Use ElevenLabs for high‑quality voice cloning – sign up at try ElevenLabs here.
- Record a short sample, run
clone_creator.pyto get a voice ID. - Build a Flask API (
app.py) that forwards text to ElevenLabs and streams back MP3. - Create a minimal HTML/JS front‑end to call
/synthesize. - Deploy the whole stack on Bluehost, the affordable, one‑click host that handles Python apps out of the box. Use the link Bluehost – the easy, affordable way to host your voice AI project to get started.
Give it a try, iterate on the UI, and maybe turn the demo into a full‑blown SaaS offering. Happy cloning! 🚀
Ready to experiment? Sign up for ElevenLabs and spin up your first voice clone, then launch it instantly on Bluehost. Your AI‑powered voice app is just a few clicks away.
Top comments (0)