How to Set Up a Voice-Enabled Blog with AI Narration
Why a Voice‑Enabled Blog? Reading long‑form articles on a screen can be tiring, especially on mobile. Adding AI‑generated narration gives your visitors the option to listen while they commute, work out, or simply relax
Why a Voice‑Enabled Blog?
Reading long‑form articles on a screen can be tiring, especially on mobile. Adding AI‑generated narration gives your visitors the option to listen while they commute, work out, or simply relax. With modern text‑to‑speech (TTS) services you can generate natural‑sounding speech in seconds, and with voice‑cloning you can keep a consistent brand voice across every post.
In this guide we’ll walk through a complete, developer‑friendly setup:
- Fetch your blog post text (Markdown, RSS, or a static file).
- Send it to ElevenLabs for high‑quality narration.
- Serve the audio files from a cheap, reliable host – we’ll use Bluehost.
- Add a tiny JavaScript player so readers can click “listen”.
By the end you’ll have a minimal Flask app that can be deployed in a few clicks, and you’ll be ready to scale it to a full‑blown voice‑enabled blog.
Prerequisites
- Basic familiarity with Python (or Node.js) and HTTP APIs.
- A GitHub repository (or any source) that contains your blog posts in Markdown.
- Accounts on ElevenLabs (sign‑up is free for limited usage) and Bluehost (the affordable shared‑hosting plan works great for small projects).
👉 Quick links – grab an ElevenLabs API key: https://try.elevenlabs.io/kr07zfuqn1bp
👉 Ready to host? Jump to Bluehost: https://bluehost.sjv.io/5k0d52
1. Get an ElevenLabs API Key
- Go to the ElevenLabs sign‑up page and create an account.
- Navigate to Dashboard → API Keys and generate a new key.
- Store it securely – we’ll reference it in an environment variable called
ELEVENLABS_API_KEY.
# On your local machine (Linux/macOS)
export ELEVENLABS_API_KEY="sk-XXXXXXXXXXXXXXXXXXXXXXXX"
Tip: When you later push to Bluehost, add the same environment variable through the cPanel → Advanced → Environment Variables UI.
2. Create a Simple Flask Service
We’ll build a tiny endpoint that receives a post slug, loads the Markdown, strips the front‑matter, and calls ElevenLabs to synthesize speech.
# app.py
import os
import markdown
import requests
from flask import Flask, jsonify, send_file, abort
app = Flask(__name__)
ELEVEN_API = "https://api.elevenlabs.io/v1/text-to-speech"
API_KEY = os.getenv("ELEVENLABS_API_KEY")
VOICE_ID = "EXAVITQu4vr4xnSDxMaL" # default voice; replace with your cloned voice ID
def markdown_to_text(md_path):
with open(md_path, "r", encoding="utf-8") as f:
md = f.read()
# Remove YAML front‑matter if present
if md.startswith("---"):
md = md.split("---", 2)[-1]
html = markdown.markdown(md)
# Very naive strip of HTML tags – good enough for demo
return "".join(html.split("<")[0::2])
def synthesize(text, filename):
headers = {
"xi-api-key": API_KEY,
"Content-Type": "application/json"
}
payload = {
"text": text,
"voice_settings": {"stability": 0.75, "similarity_boost": 0.85}
}
response = requests.post(f"{ELEVEN_API}/{VOICE_ID}", json=payload, headers=headers)
response.raise_for_status()
# Save MP3 locally
with open(filename, "wb") as f:
f.write(response.content)
@app.route("/audio/<slug>")
def get_audio(slug):
md_path = f"posts/{slug}.md"
if not os.path.exists(md_path):
abort(404, "Post not found")
audio_path = f"static/{slug}.mp3"
# Regenerate only if missing or you want fresh audio
if not os.path.exists(audio_path):
text = markdown_to_text(md_path)
synthesize(text, audio_path)
return send_file(audio_path, mimetype="audio/mpeg")
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
What the code does
| Step | Description |
|---|---|
| markdown_to_text | Loads a Markdown file, removes optional YAML front‑matter, converts to HTML, then strips tags to get plain text. |
| synthesize | Calls the ElevenLabs TTS endpoint, passing the text and a small set of voice settings. The binary MP3 response is saved to static/. |
| /audio/ | Public endpoint that returns the MP3 for a given post slug. If the file doesn’t exist yet, it’s generated on‑the‑fly. |
Remember: Replace
VOICE_IDwith the ID of a voice you’ve cloned in ElevenLabs if you want a custom brand voice. You can retrieve it from the ElevenLabs dashboard.
3. Front‑End: Add a “Listen” Button
If you already have a static site (e.g., Jekyll, Hugo, or a plain HTML blog), just drop this snippet into your post template.
<button id="listenBtn">🔊 Listen</button>
<audio id="player" controls style="display:none;"></audio>
<script>
document.getElementById('listenBtn').addEventListener('click', async () => {
const slug = window.location.pathname.split('/').pop().replace('.html','');
const audioUrl = `/audio/${slug}`;
const player = document.getElementById('player');
player.src = audioUrl;
player.style.display = 'block';
player.play();
});
</script>
When a visitor clicks Listen, the browser fetches the MP3 from your Flask service and starts playback instantly. No third‑party player needed.
4. Deploy to Bluehost – The Easy, Affordable Way
Bluehost’s shared‑hosting plans include cPanel, Python support, and a one‑click Git deployment. Here’s a quick rundown:
- Create a new site in your Bluehost dashboard. Choose the “WordPress/Custom PHP” plan (the cheapest tier works).
- In cPanel → Software → Setup Python App, select Python 3.10 (or newer).
- Set the app directory to something like
~/myvoiceblog. - Click Create – Bluehost will spin up a virtualenv for you.
- Use the SSH terminal (or the “Terminal” button in cPanel) to clone your repo:
git clone https://github.com/yourname/voice‑blog.git ~/myvoiceblog
cd ~/myvoiceblog
- Install dependencies:
source /opt/python/3.10/venv/bin/activate # path may vary; Bluehost shows it
pip install -r requirements.txt
- In the Python App UI, set the Startup File to
app.pyand the Application Entry Point toapp. Save the changes. - Add your
ELEVENLABS_API_KEYunder Environment Variables.
Your Flask service is now live at https://yourdomain.com. The /audio/<slug> endpoint works just like it did locally.
Why Bluehost? It’s the low‑cost, one‑click solution for developers who want to focus on code rather than server plumbing. You get a full cPanel suite, automatic backups, and 24/7 support—all for under $5/month.
5. Optional: Using cURL for Quick Tests
Before wiring the front‑end, you can verify the TTS endpoint with a simple curl command:
curl -X POST "https://api.elevenlabs.io/v1/text-to-speech/EXAVITQu4vr4xnSDxMaL" \
-H "xi-api-key: $ELEVENLABS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"Hello, world! This is a quick test of ElevenLabs TTS.", "voice_settings":{"stability":0.75,"similarity_boost":0.85}}' \
--output hello.mp3
Play hello.mp3 locally to hear the result. Once you’re happy, the Flask wrapper does the same thing automatically.
6. Tips & Best Practices
| Area | Recommendation |
|---|---|
| Caching | Store generated MP3s in a CDN (Cloudflare or BunnyCDN) to reduce latency and avoid hitting ElevenLabs rate limits. |
| Voice Cloning | Use ElevenLabs’ voice‑cloning feature to create a unique narrator that matches your brand. Upload a few minutes of clean audio, then reference the returned voice_id. |
| Chunking | For very long posts, split the text into ~2,000‑character chunks to stay within ElevenLabs payload limits and to avoid timeouts. |
| Accessibility | Add <track kind="captions"> tags with auto‑generated transcripts for hearing‑impaired users. |
| Cost Monitoring | ElevenLabs charges per generated minute. Keep an eye on usage in the dashboard and set a daily quota if needed. |
7. Scaling Up
Once the prototype works, you can:
- Add a background worker (e.g., Celery + Redis) to pre‑render audio for every new post, so users never wait for on‑the‑fly generation.
- Expose a GraphQL API that returns both the post content and the audio URL in a single request.
-
Integrate with static site generators (like Hugo) via a build‑time script that calls the Flask service and writes the MP3 files into the
static/folder before deployment.
All of these steps can still live on Bluehost; the platform supports Node.js, Ruby, and even Docker containers on higher‑tier plans if you ever outgrow Flask.
Wrap‑Up
You now have a complete, production‑ready pipeline:
- Write your article in Markdown.
- Let Flask call ElevenLabs (via the easy‑to‑use API) and store the resulting MP3.
- Serve the audio from a Bluehost‑hosted app that scales with your traffic.
- Add a tiny front‑end player for a seamless “listen” experience.
Give it a spin, experiment with different voice settings, and watch how much longer visitors stay on your site when they can just press play.
Ready to give your blog a voice?
- Grab your ElevenLabs API key and start generating natural narration today: https://try.elevenlabs.io/kr07zfuqn1bp
- Deploy the Flask service in minutes with the affordable, hassle‑free hosting from Bluehost: https://bluehost.sjv.io/5k0d52
Happy coding, and enjoy the sound of your own words!
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.