Converting written blog posts to audio is an easy way to reach more people. Many users prefer to listen while traveling or exercising. Others enjoy both reading and listening options.
With Openai Text to speech model, you can create a neat service that takes a blog URL or pasted text and produces a natural-sounding audio file.
In this article, you will learn how to build this system end-to-end. You’ll learn how to fetch blog content, send it to Openai’s audio API, save the output as an MP3 file, and serve everything up and down. Fastpy App
Finally, you’ll also create a minimal user interface and deploy it to Sevilla so that anyone can upload text and download audio without touching code.
Table of Contents
Understanding the main idea
There are only three main parts of the blog-to-audio service. The first part takes the blog link or text and cleans it up. The second part sends plain text to OpenAI’s text-to-speech model. The third part returns the final MP3 file to the user.
Openai’s speech generation is easy to use. You send text, choose a voice, and get audio back. The quality is high and works well even for long posts. This means you don’t have to worry about training models or tuning sounds.
The only work left is to make the system easy to use. That’s where FastPy and a small HTML form help. They wrap your code into a web service so anyone can try it.
How to set up your project
Create a folder for your project. Inside that, create a file called main.py. Later you will also need a basic HTML file.
Install your libraries with PIP:
pip install fastapi uvicorn requests beautifulsoup4 python-multipart
Fastpy gives you a simple background. Requests module helps to download blog pages. beautysoup Helps remove HTML tags and extract readable text. Python supports uploading multipart form data.
You also need to install the OpenAI client:
pip install openai
Make sure you have the OpenAI API key ready. Before running the app, set it in your terminal:
export OPENAI_API_KEY="your-key"
On Windows, you can:
setx OPENAI_API_KEY "your-key"
How to fetch and clean blog content
To convert a blog to audio, you must first extract the main text of the article. You fetch the page with the requests and can parse it with elegant sauce.
Below is a simple function that does this.
import requests
from bs4 import BeautifulSoup
def extract_text_from_url(url: str) -> str:
response = requests.get(url, timeout=10)
html = response.text
soup = BeautifulSoup(html, "html.parser")
paragraphs = soup.find_all("p")
text = " ".join(p.get_text(strip=True) for p in paragraphs)
return text
Here is what happens step by step.
The function downloads the page.
BuitySOUP reads the HTML and finds all paragraph tags.
It extracts the text in each paragraph and concatenates them into one long string.
This gives you a clean version of the blog post without ads or layout code.
If the user pastes text instead of a URL, you can skip this part and use the text as is.
How to send text to OpenAI for audio
Openai’s text-to-speech API makes this part of the job much easier. You send a message with text and choose a sound like Egypt or verse. The API returns the raw audio bytes. You can save these bytes as an MP3 file.
Here is a helper function to convert text to audio:
from openai import OpenAI
client = OpenAI()
def text_to_audio(text: str, output_path: str):
audio = client.audio.speech.create(
model="gpt-4o-mini-tts",
voice="alloy",
input=text
)
with open(output_path, "wb") as f:
f.write(audio.read())
This function calls OpenaiClient and passes the text, model name, and voice selection. .read() The method outputs a binary audio stream. This completes the writing process to an MP3 file.
If the blog post is too long, you may want to limit the length of the text or extract the text and join the audio files later. But for most blogs, the model can handle the entire text in one request.
How to Create a FastPy Backend
Now you can wrap both steps into a simple fastpy server. This server will accept either a URL or pasted text. It will convert the content to audio and return an MP3 file as a response.
Here is the full backend code:
from fastapi import FastAPI, Form
from fastapi.responses import FileResponse
import uuid
import os
app = FastAPI()
@app.post("/convert")
def convert(url: str = Form(None), text: str = Form(None)):
if not url and not text:
return {"error": "Please provide a URL or text"}
if url:
try:
text_content = extract_text_from_url(url)
except Exception:
return {"error": "Could not fetch the URL"}
else:
text_content = text
file_id = uuid.uuid4().hex
output_path = f"audio_{file_id}.mp3"
text_to_audio(text_content, output_path)
return FileResponse(output_path, media_type="audio/mpeg")
How it works User sends form data with someone url or text. The server checks which one exists.
If there is a url, it extracts the text with the first function. If there is no URL, it uses the supplied text directly. A unique file name is created for each application. The audio file is then generated and returned as an MP3 download.
You can run the server like this:
uvicorn main:app --reload
Open your browser http://localhost:8000. You won’t see the UI yet, but the API endpoint is working. You can check this using a tool like Postman or by creating the next section next.
How to Add a Simple User Interface
A service is much easier to use when it has a clean UI. Below is a simple HTML page that sends either a URL or text to your FastPi backend. Save this file as index.html In the same folder:
html>
<html>
<head>
<title>Blog to Audiotitle>
<style>
body { font-family: Arial, padding: 40px; max-width: 600px; margin: auto; }
input, textarea { width: 100%; padding: 10px; margin-top: 10px; }
button { padding: 12px 20px; margin-top: 20px; cursor: pointer; }
style>
head>
<body>
<h2>Convert Blog to Audioh2>
<form action="/convert" method="post">
<label>Blog URLlabel>
<input type="text" name="url" placeholder="Enter a blog link">
<p>or paste text belowp>
<textarea name="text" rows="10" placeholder="Paste blog text here">textarea>
<button type="submit">Convert to Audiobutton>
form>
body>
html>
This page gives the user two options. They can type a URL or paste text. The form sends data /convert Using the post application. The response will be an MP3 file, so the browser will download it.
To serve the HTML file, add this path to your main.py:
from fastapi.responses import HTMLResponse
@app.get("/")
def home():
with open("index.html", "r") as f:
html = f.read()
return HTMLResponse(html)
Now, when you visit the main URL, you will see a clean look.

When you submit the URL, the server will process your request and give you the audio file.

very good Our text to audio service is working. Now put it into production.
How to deploy your service in Seoul
You can choose any cloud provider, such as AWS, Digitalosine, or others, to host your service. I’ll use Siola for this example.
Seoul is a developer-friendly PAAS provider. It offers application hosting, database, object storage, and static site hosting for your projects.
Each platform will charge you to create a cloud resource. Siola comes with a $50 credit for our use, so we won’t incur any costs for this instance.
Let’s push this project to GitHub so that we can connect our repository to Seolla. We can also enable auto-deployments so that any new changes to the repository are automatically deployed.
You can too Fork my collection From here
Login Click on Seola and Applications -> Create New Application. You can see the option to link your GitHub repository to create a new application.

Use the default settings. Click on “Create Application”. Now we need to add our openui API key to the environment variables. Once the application is created click on the “Environment Variables” section, and save OPENAI_API_KEY value as an environmental variable.

Now we are ready to deploy our application. Click on “Deploy” and click on “Deploy Now”. The deployment will take 2–3 minutes to complete.

Once done, click on “View App”. You will see the request ending with the URL sevalla.app . This is your new root URL. You can change localhost:8000 With this URL and start using it.

Congratulations! Your blog-to-audio service is now live. You can extend it by adding other capabilities and pushing your code to GitHub. Seola will automatically deploy your application to production.
The result
Now you know how to build a complete blog-to-audio service using OpenAI. You learned how to fetch blog text, convert it to speech, and present it with FastPy. You also learned how to create a simple user interface, allowing people to try it without any setup.
With this foundation, you can convert any written material into smooth, natural audio. This can help creators reach a wider audience, increase reach, and provide more ways for users to enjoy content.
Hope you enjoyed this article. Sign up for my free newsletter turingtalks.ai For more tutorials on AI. You can too Visit my website.