How to Add AI Voice to Your Django App A developer published a walkthrough for adding AI text-to-speech to a Django application using the ElevenLabs REST API, with async httpx calls wrapped in a reusable synthesize() function and an example /speak/ endpoint that returns MP3 audio. The guide also covers cloning a user's voice from uploaded samples and storing the resulting voice_id on the user model, plus notes on streaming audio for real-time chatbot use cases. Voice has become the new “screen” for many users. From hands‑free navigation to accessibility, integrating AI‑generated speech can make your Django project feel more natural and inclusive. Whether you’re building a customer‑support chatbot, an audiobook generator, or a language‑learning platform, adding text‑to‑speech TTS is a quick way to boost engagement. When you need a reliable, high‑quality TTS service that supports voice cloning, ElevenLabs is a popular choice. Their API offers dozens of realistic voices, fine‑grained control over speaking rate, pitch, and more—all wrapped in a developer‑friendly REST interface. If you’re looking for a service that’s easy to set up and scales with your Django app, try ElevenLabs: https://try.elevenlabs.io/kr07zfuqn1bp https://try.elevenlabs.io/kr07zfuqn1bp .env file: ELEVENLABS API KEY=sk your key here While you can use curl or any HTTP library, Django developers often prefer httpx for async support. pip install httpx Create a new module, e.g., voice.py , and add: python import os import httpx from django.conf import settings ELEVENLABS API URL = "https://api.elevenlabs.io/v1/text-to-speech" async def synthesize text: str, voice id: str = "Bella", output path: str = None : """ Convert text to speech using ElevenLabs. """ headers = { "accept": "audio/mpeg", "xi-api-key": settings.ELEVENLABS API KEY, "Content-Type": "application/json", } payload = { "text": text, "voice settings": { "stability": 0.5, "similarity boost": 0.75, }, } async with httpx.AsyncClient as client: resp = await client.post f"{ELEVENLABS API URL}/{voice id}", json=payload, headers=headers resp.raise for status audio bytes = resp.content if output path: with open output path, "wb" as f: f.write audio bytes return audio bytes The voice id parameter can be any voice you’ve enabled in your ElevenLabs dashboard. “Bella” is a default, but you can list all voices with another endpoint if you need to present options to users. Here’s a quick example of an endpoint that returns an audio file directly: python from django.http import HttpResponse from .voice import synthesize async def speak request : """ API endpoint: /speak/?text=Hello%20world Returns an MP3 file generated by ElevenLabs. """ text = request.GET.get "text", "Hello, world " audio = await synthesize text, voice id="Bella" return HttpResponse audio, content type="audio/mpeg" Add the URL in urls.py : python from django.urls import path from .views import speak urlpatterns = path "speak/", speak, name="speak" , Now, visiting /speak/?text=Good%20morning%20everyone will stream a polished voice directly in the browser. If you want your users to speak in a personalized voice, ElevenLabs supports cloning with just a few samples. The process: voice id you’ll use in subsequent requests. synthesize function. python Example: cloning a user’s voice async def clone voice uploaded audio : headers = {"xi-api-key": settings.ELEVENLABS API KEY} files = {"audio file": "sample.wav", uploaded audio, "audio/wav" } async with httpx.AsyncClient as client: resp = await client.post "https://api.elevenlabs.io/v1/voices", headers=headers, files=files, resp.raise for status return resp.json "voice id" You can expose this as a Django view that accepts file uploads. Once the voice is cloned, store the voice id in your user model for later use. For real‑time applications e.g., a chatbot that speaks instantly , you’ll want to stream the audio rather than buffering the whole file. ElevenLabs supports streaming via WebSockets or by returning raw audio/mpeg chunks. In Django, you can use StreamingHttpResponse : python from django.http import StreamingHttpResponse async def stream speak request : text = request.GET.get "text", "Hello" async def generator : Simulate streaming by yielding chunks audio = await synthesize text, voice id="Bella" yield audio return StreamingHttpResponse generator , content type="audio/mpeg" For production deployments, consider: curl Example If you’re debugging or want to try it from the terminal: curl -X POST "https://api.elevenlabs.io/v1/text-to-speech/Bella" \ -H "Content-Type: application/json" \ -H "xi-api-key: $ELEVENLABS API KEY" \ -d '{"text":"Hello from ElevenLabs ","voice settings":{"stability":0.5,"similarity boost":0.75}}' \ --output hello.mp3 Open hello.mp3 to hear the result. Adding AI voice to a Django app is surprisingly straightforward: By following the snippets above, you’ll have a functional TTS endpoint in minutes, ready to be integrated into your UI, API, or background workers. Ready to give your Django app a voice? Dive into ElevenLabs today and transform text into natural, expressive speech: https://try.elevenlabs.io/kr07zfuqn1bp https://try.elevenlabs.io/kr07zfuqn1bp Happy coding