Build an AI Audiobook Narrator with Telnyx AI Inference, TTS, and Cloud Storage | Low Latency Club
Skip to main content
Blog<br>Code-first technical deep dives
Glossary<br>Voice AI & telecom terminology
Developer Docs<br>API references & integration guides
GitHub<br>Open-source repos & SDKs
Articles<br>Tutorials & support articles
AI Agents<br>Build voice AI agents
Voice API<br>Programmable voice calls
ClawHouse<br>AI-powered voice assistant
ClawdTalk<br>Conversational AI platform
Events<br>Videos<br>Podcast<br>Integrations
Resources
Blog<br>Code-first technical deep dives
Glossary<br>Voice AI & telecom terminology
Developer Docs<br>API references & integration guides
GitHub<br>Open-source repos & SDKs
Articles<br>Tutorials & support articles
Products
AI Agents<br>Build voice AI agents
Voice API<br>Programmable voice calls
ClawHouse<br>AI-powered voice assistant
ClawdTalk<br>Conversational AI platform
Contact us<br>Join our Slack
Turning a manuscript into a narrated audiobook traditionally means hiring a voice actor, booking studio time, and accepting that revisions cost hours of re-recording. This walkthrough builds a Flask app that takes raw text, uses AI Inference to chunk it into chapters with pacing and emotion cues, narrates each chapter with text-to-speech, and stores the resulting MP3s in Telnyx Cloud Storage with presigned URLs for playback.
The canonical code example lives in the Telnyx code examples repo:
https://github.com/team-telnyx/telnyx-code-examples/tree/main/ai-audiobook-narrator-python
What This Example Builds
A single-file Flask app with five endpoints:
MethodPathPurposePOST/books/narrateSubmit text for audiobook narration (the main pipeline)GET/books/Retrieve a specific book and its chapter audio URLsGET/booksList all books processed so farGET/voicesList available narrator voicesGET/healthService health check<br>The pipeline runs in three stages. AI Inference splits the submitted text into chapters and adds narration cues (tone, pacing, emphasis). Text-to-speech renders each chapter as an MP3 using a consistent voice. Cloud Storage holds the final audio and returns a time-limited presigned GET URL for each chapter so callers can stream the result without handling long-lived credentials.
Why This Matters
The audiobook narrator exercises three Telnyx AI products in a single request flow — AI Inference, TTS, and Cloud Storage — and returns a tangible artifact (an actual MP3 file) instead of a text completion. That makes it a useful reference for anyone building content-generation pipelines where the output is media, not text.
Developers use this pattern as the foundation for:
Self-publishing tools — Convert manuscripts to audiobooks for distribution platforms that require audio
Accessibility services — Turn written content into audio for visually impaired readers
Content repurposing — Generate audio versions of blog posts, documentation, or newsletters
Podcast pre-production — Draft narration tracks that a human host can later rerecord or remix
Multi-language narration — Run the same text through different TTS voices and languages for localized audio
Products Used
telnyx_products: [AI Inference, TTS, Cloud Storage]<br>Telnyx AI Inference exposes an OpenAI-compatible API for chat completions. Telnyx TTS generates speech from text via POST /v2/ai/generate. Telnyx Cloud Storage is S3-compatible, so the AWS SDK (boto3) talks to it directly — the Telnyx API key is used as both the access key and the secret key, and the endpoint host is region-scoped (https://{region}.telnyxcloudstorage.com).
Architecture
POST /books/narrate<br>+----------------------+<br>| AI Inference | chunks text into chapters,<br>| /v2/ai/chat/ | adds tone + pacing cues<br>| completions |<br>+----------+-----------+<br>+----------------------+<br>| TTS Generate | renders each chapter as MP3<br>| /v2/ai/generate | with a consistent voice<br>+----------+-----------+<br>+----------------------+<br>| Cloud Storage (S3) | PutObject per chapter,<br>| boto3 put_object | presigned GET URL returned<br>+----------+-----------+<br>+---> JSON response with storage_urls[]<br>The Code
The full app is 242 lines in a single app.py. The key pieces:
Configuration and storage client. The Telnyx API key is loaded from the environment and used for both the REST API (Inference, TTS) and the S3 client (Cloud Storage). The S3 client is pointed at the region-scoped Telnyx endpoint with s3v4 signing:
import os, boto3<br>from botocore.config import Config
TELNYX_API_KEY = os.getenv("TELNYX_API_KEY")<br>REGION = os.getenv("TELNYX_STORAGE_REGION", "us-central-1")
s3 = boto3.client(<br>"s3",<br>endpoint_url=f"https://{REGION}.telnyxcloudstorage.com",<br>aws_access_key_id=TELNYX_API_KEY,<br>aws_secret_access_key=TELNYX_API_KEY,<br>region_name=REGION,<br>config=Config(signature_version="s3v4"),<br>AI Inference call. A system prompt instructs the model to break the text into chapters and return a JSON array with chapter_number, chapter_title, narration_text, tone, and pacing fields. The response is parsed as JSON, with a fallback to paragraph...