Build an AI Audiobook Narrator with Telnyx AI Inference, TTS, and Cloud Storage
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: A single-file Flask app with five endpoints: 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-limite
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: A single-file Flask app with five endpoints: 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-limite
d presigned GET URL for each chapter so callers can stream the result without handling long-lived credentials. 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: telnyx_products: [AI Inference, TTS, Cloud Storage] 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 ( ). POST /books/narrate | v +----------------------+ | AI Inference | chunks text into chapters, | /v2/ai/chat/ | adds tone + pacing cues | completions | +----------+-----------+ | v +----------------------+ | TTS Generate | renders each chapter as MP3 | /v2/ai/generate | with a consistent voice +----------+-----------+ | v +----------------------+ | Cloud Storage (S3) | PutObject per chapter, | boto3 put_object | presigned GET URL returned +----------+-----------+ | +---> JSON response with storage_urls[] The Code The full app is 242 lines in a single . 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 from import Config TELNYX_API_KEY = ("TELNYX_API_KEY") REGION = ("TELNYX_STORAGE_REGION", "us-central-1") s3 = ( "s3", aws_access_key_id=TELNYX_API_KEY, aws_secret_access_key=TELNYX_API_KEY, config=Config(signature_version="s3v4"), ) 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 splitting if the model returns malformed JSON: def inference(messages, max_tokens=4000): resp = (f"{API}/ai/chat/completions", headers=HEADERS, json={ "model": AI_MODEL, "messages": messages, "max_tokens": max_tokens, "temperature": 0.3 }, timeout=60) return ()["choices"][0]["message"]["content"] TTS generation. Each chapter's narration text is sent to POST /v2/ai/generate with the chosen voice and output_format: mp3 . The response body is the raw MP3 bytes: def tts_generate(text, voice=None): resp = (f"{API}/ai/generate", headers=HEADERS, json={ "text": text, "output_format": "mp3" }, timeout=60) return Upload to Cloud Storage. Each chapter MP3 is uploaded with put_object , then a presigned GET URL valid for one hour is returned so the caller can stream the audio without exposing long-lived credentials: def upload_to_storage(bucket, key, data, content_type="audio/mpeg"): s3.put_object(Bucket=bucket, Key=key, Body=data, ContentType=content_type) return s3.generate_presigned_url( "get_object", Params={"Bucket": bucket, "Key": key}, ExpiresIn=3600 ) The narrate endpoint. Wires the three stages together, with graceful fallback if the AI chunking returns malformed JSON (splits the text by paragraphs instead): @ ("/books/narrate", methods=["POST"]) data = request.get_json()
or {} if not data: return jsonify({"error": "invalid request body"}), 400 title = ("title", "Untitled") text = ("text", "") voice = ("voice", DEFAULT_VOICE) if not text: return jsonify({"error": "Provide 'text' to narrate"}), 400 book_id = f"book-{uuid.uuid4().hex[:8]}" # Step 1: AI chunks text into chapters with narration cues try: chunking_result = inference([ {"role": "system", "content": "You are an audiobook production assistant..."}, {"role": "user", "content": text[:15000]} except : # Fallback: split by paragraphs paragraphs = [ () for p in ("\n\n") if ()] chapters = [{ "chapter_title": f"Chapter {i + 1}", "tone": "warm", "pacing": "moderate" } for i, chunk in enumerate(paragraphs)] # Step 2 + 3: TTS per chapter â Cloud Storage for chapter in chapters: audio = tts_generate(chapter["narration_text"], voice=voice) key = f"{book_id}/chapter-{chapter['chapter_number']:02d}.mp3" url = upload_to_storage(BUCKET_NAME, key, audio) books[book_id]["storage_urls"].append(url) return jsonify({ "book_id": book_id, "title": title, "status": "complete", "chapters": len(books[book_id]["chapters"]), "storage_urls": books[book_id]["storage_urls"] }), 201 Run It git clone cd telnyx-code-examples/ai-audiobook-narrator-python cp . .env # add TELNYX_API_KEY, optionally tune AI_MODEL, TTS_MODEL, BUCKET_NAME pip install -r python The server starts on . Create a bucket named audiobooks in the Telnyx Portal (or set BUCKET_NAME to an existing bucket) and submit a chunk of text: curl -X POST \ -H "Content-Type: application/json" \ -d '{ "title": "The Future of Infrastructure", "text": "Chapter 1: The shift from cloud-edge to carrier-edge compute is changing where latency-sensitive workloads run...", "voice": "nova" }' The response includes a book_id and a list of presigned storage_urls , one per chapter: { "title": "The Future of Infrastructure", "status": "complete", "chapters": 3, "voice": "nova", " " " ] } Open any storage_url in a browser or stream it from a client to hear the narrated chapter. The app exposes five narrator voices out of the box: List them at any time: curl Pass any voice identifier in the voice field of the /books/narrate request. This example uses an in-memory dict for book metadata, which is fine for local testing but loses state on restart. For production: Do I need an existing Cloud Storage bucket before running this? Yes. Create a bucket in the Telnyx Portal and set BUCKET_NAME in .env to match. The app does not create the bucket for you. What happens if the AI returns malformed JSON for the chapter split? The app catches and falls back to splitting the text by double-newline paragraphs. Each paragraph becomes a chapter with default tone: warm and pacing: moderate . Narration still completes â you just lose the AI's tone and pacing direction. Which AI model is used by default? The default is moonshotai/Kimi-K2.6 (set in . and overridable via AI_MODEL ). Any model available on Telnyx AI Inference works â see the models list for options. Can I use a different TTS voice per chapter? Not in this example â the voice is set once per request and used for every chapter. To vary voices per chapter, extend the narrate_book loop to read chapter["voice"] from the AI's response and pass it to tts_generate . How long do the presigned URLs last? One hour ( ExpiresIn=3600 ). The stored MP3s persist in the bucket; only the URL expires. Generate a fresh presigned URL with s3.generate_presigned_url whenever you need a new one. Is the
uploaded audio public? No. The bucket is private by default. Only the presigned URL grants time-limited read access. To make audio publicly accessible (e.g., for public-domain audiobooks), set a public read policy on the bucket in the Telnyx Portal. What is the maximum input text length? The chunking step truncates input to 15,000 characters per request. For longer manuscripts, split the source into sections on the client and submit each as a separate /books/narrate request, then stitch the resulting storage_urls together. Can I narrate in languages other than English? Yes â Telnyx TTS supports multiple languages. The AI Inference prompt is in English, but you can edit the system message in to chunk in another language, and pass a language-appropriate voice to tts_generate .
AI数据中心隐含水耗达官方数据数十倍 韩国巨型项目风险高
据《华尔街日报》报道,美国劳伦斯伯克利国家实验室最新报告指出,AI数据中心的“间接水耗”(发电过程中蒸发的水)平均是服务器直接冷却用水的12倍,但多数科技巨头仅披露直接用水。谷歌2023年直接用水虽达109亿加仑,但研究估算其隐含水耗至少为直接用水的3倍;Meta 2024年间接水耗超过直接用水20倍,达190亿加仑,却未制定具体减排措施。此外,约三分之二的新建数据中心位于菲尼克斯等长期缺水地区,非营利组织警告当地水需求到2031年将超城市总水量的20%。Nvidia虽研发无水冷却系统,但全球数据中心改造代价高昂。韩国正推进的“三大巨型项目”大规模兴建AI数据中心,因缺乏水资源对策被业界认为存在严重隐患。 #AI #数据中心 #水资源 #环境 #韩国 #科技新闻 #隐含水耗
据《华尔街日报》报道,美国劳伦斯伯克利国家实验室最新报告指出,AI数据中心的“间接水耗”(发电过程中蒸发的水)平均是服务器直接冷却用水的12倍,但多数科技巨头仅披露直接用水。谷歌2023年直接用水虽达109亿加仑,但研究估算其隐含水耗至少为直接用水的3倍;Meta 2024年间接水耗超过直接用水20倍,达190亿加仑,却未制定具体减排措施。此外,约三分之二的新建数据中心位于菲尼克斯等长期缺水地区,非营利组织警告当地水需求到2031年将超城市总水量的20%。Nvidia虽研发无水冷却系统,但全球数据中心改造代价高昂。韩国正推进的“三大巨型项目”大规模兴建AI数据中心,因缺乏水资源对策被业界认为存在严重隐患。 #AI #数据中心 #水资源 #环境 #韩国 #科技新闻 #隐含水耗
AI智能体系统缺乏可见性?开发者用LangSmith实现全流程追踪
开发者Hugo Santana为其构建的多智能体系统引入了可观测性平台LangSmith。此前,他搭建了一个由6个智能体组成的研究系统,用于追踪AI应用案例、工具和供应商,并包含翻译和内容匹配等功能。随着系统扩展至更多智能体,虽然能看到最终输出和日志,但无法清晰了解每个智能体的运行细节,如token消耗、任务失败原因和耗时。LangSmith提供了完整的追踪功能,将智能体活动转化为可搜索的运行记录,包含输入输出、时长、状态、成本及错误信息。这一集成使他能够监控效率、可靠性,并为多智能体产品的优化奠定基础。LangSmith框架无关的特性使其能无缝对接自定义系统,且开源的API设计便于AI编码工具辅助集成。 #AI #智能体 #可观测性 #LangSmith #多智能体系统 #技术工具
开发者Hugo Santana为其构建的多智能体系统引入了可观测性平台LangSmith。此前,他搭建了一个由6个智能体组成的研究系统,用于追踪AI应用案例、工具和供应商,并包含翻译和内容匹配等功能。随着系统扩展至更多智能体,虽然能看到最终输出和日志,但无法清晰了解每个智能体的运行细节,如token消耗、任务失败原因和耗时。LangSmith提供了完整的追踪功能,将智能体活动转化为可搜索的运行记录,包含输入输出、时长、状态、成本及错误信息。这一集成使他能够监控效率、可靠性,并为多智能体产品的优化奠定基础。LangSmith框架无关的特性使其能无缝对接自定义系统,且开源的API设计便于AI编码工具辅助集成。 #AI #智能体 #可观测性 #LangSmith #多智能体系统 #技术工具