How to Add AI Narration to Your Blog Posts
Why Add AI Narration to Your Blog? If you’ve ever scrolled through a long article and thought, “I wish I could listen to this while I’m on the go,” you’re not alone. Adding a spoken version of your post turns a static
Why Add AI Narration to Your Blog?
If you’ve ever scrolled through a long article and thought, “I wish I could listen to this while I’m on the go,” you’re not alone. Adding a spoken version of your post turns a static page into a multi‑modal experience that:
- Boosts accessibility for visually‑impaired readers and non‑native speakers.
- Increases dwell time – people tend to stay longer when they can listen.
- Improves SEO – Google’s algorithms reward rich media, and an audio file can be indexed as a separate asset.
All of this sounds great, but building a high‑quality voice pipeline from scratch used to be a nightmare. Today, modern text‑to‑speech (TTS) services give you realistic, expressive narration with just a few lines of code. In this guide we’ll walk through the whole process, from getting an API key to embedding the audio player in a static blog.
The Tool of Choice: ElevenLabs
When it comes to developer‑friendly TTS, ElevenLabs stands out for three reasons:
- Natural‑sounding voices that can be customized per author or brand.
- Voice cloning – upload a few minutes of your own voice and let the model speak for you.
- Simple REST API with generous free tier and clear documentation.
If you haven’t signed up yet, grab your free credits through the affiliate link above and you’ll be ready to make your first request in seconds.
Getting Your API Key
- Sign up at the link above.
- Navigate to Dashboard → API Keys.
- Click Create new key, give it a name (e.g., “blog‑narration”), and copy the generated token.
Treat this token like a password – keep it out of client‑side code and version control.
A Minimal Python Script
Below is a quick Python snippet that sends a paragraph to ElevenLabs and saves the resulting MP3. We’ll use the requests library, which is part of most Python installations.
import requests
API_KEY = "YOUR_ELEVENLABS_API_KEY"
VOICE_ID = "21m00Tcm4TlvDq8ikWAM" # Default “Rachel” voice; replace with your own
def synthesize(text: str, output_path: str = "output.mp3"):
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,
"model_id": "eleven_monolingual_v1",
"voice_settings": {
"stability": 0.75,
"similarity_boost": 0.85
}
}
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status() # Raise if something went wrong
# Write the binary audio to a file
with open(output_path, "wb") as f:
f.write(response.content)
print(f"Saved narration to {output_path}")
# Example usage
article = """
Artificial intelligence has made it possible to turn text into speech that sounds
almost human. In this post we’ll explore how to add AI narration to your blog.
"""
synthesize(article)
What’s happening?
- We POST JSON to the
/text-to-speech/{voice_id}endpoint. -
model_idselects the underlying TTS model – the default works well for most English content. -
voice_settingslet you tweak stability (smoothness) and similarity boost (how “confident” the voice sounds).
Run the script, and you’ll get an output.mp3 ready to embed.
Doing the Same Thing with cURL
If you prefer a quick terminal test, here’s the equivalent curl command:
curl -X POST "https://api.elevenlabs.io/v1/text-to-speech/21m00Tcm4TlvDq8ikWAM" \
-H "xi-api-key: YOUR_ELEVENLABS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "Your blog post goes here. ElevenLabs makes the voice sound natural.",
"model_id": "eleven_monolingual_v1",
"voice_settings": {"stability":0.75,"similarity_boost":0.85}
}' \
--output narration.mp3
Replace YOUR_ELEVENLABS_API_KEY and the text payload with your own content. The --output flag writes the binary MP3 directly to narration.mp3.
JavaScript (Fetch) for Server‑Side Rendering
If your blog runs on Node.js or you want to generate audio during a build step, the node-fetch package does the trick:
const fetch = require('node-fetch');
const fs = require('fs');
const API_KEY = 'YOUR_ELEVENLABS_API_KEY';
const VOICE_ID = '21m00Tcm4TlvDq8ikWAM';
async function synthesize(text) {
const url = `https://api.elevenlabs.io/v1/text-to-speech/${VOICE_ID}`;
const response = await fetch(url, {
method: 'POST',
headers: {
'xi-api-key': API_KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify({
text,
model_id: 'eleven_monolingual_v1',
voice_settings: { stability: 0.75, similarity_boost: 0.85 }
})
});
if (!response.ok) {
const err = await response.text();
throw new Error(`ElevenLabs error: ${err}`);
}
const buffer = await response.buffer();
fs.writeFileSync('narration.mp3', buffer);
console.log('Saved narration.mp3');
}
// Example usage
synthesize('Welcome to the future of blog narration with ElevenLabs.');
Again, keep the API key on the server side – never expose it in the browser.
Voice Cloning: Making the Narration Your Own
One of the most exciting features of ElevenLabs is voice cloning. After you upload 30‑60 seconds of clean speech (your own voice, a brand mascot, etc.), the service creates a custom voice model you can reuse forever.
Steps to clone:
- In the dashboard, go to Voice Lab → Create Voice.
- Follow the upload wizard – the UI will guide you through recording or uploading a WAV file.
- Once the model is ready, note the new
voice_id. Use it in the same API calls shown above.
Cloned voices give your blog a unique auditory signature, turning a generic TTS into a personal podcast‑like experience.
Embedding the Audio Player
Most static site generators (Hugo, Jekyll, Eleventy) allow you to drop an <audio> tag directly into your markdown. After you generate narration.mp3, copy it into your static/ folder and add:
<audio controls preload="metadata">
<source src="/audio/narration.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
If you want a fancier UI, the open‑source library Plyr works nicely and can be added with a single script tag.
Automating the Whole Workflow
For a truly hands‑free pipeline, you can hook the TTS step into your CI/CD process:
-
GitHub Action – on each push to
main, run a Python script that reads the latest markdown, strips front‑matter, calls ElevenLabs, and stores the MP3 next to the post. - Netlify Build Plugin – write a small plugin that executes the same script during the build phase.
That way, every new article automatically gets a spoken counterpart without manual steps.
TL;DR – Quick Checklist
- Sign up at ElevenLabs and grab an API key.
- Choose a voice (default or cloned) and note its
voice_id. - Use the Python, cURL, or JavaScript examples to generate an MP3 from your post text.
- Save the MP3 to your static assets folder and embed it with an
<audio>tag. - (Optional) Automate the process in your build pipeline for zero‑touch updates.
Give It a Spin!
Adding AI narration is now a matter of a few API calls and a tiny bit of scripting. With ElevenLabs, you get studio‑grade quality without the hassle of managing your own neural‑TTS models.
Ready to make your blog audible? Grab your free credits via the affiliate link, generate your first narration, and watch your engagement metrics climb. Happy coding, and enjoy the sound of your own words!
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.