Module 3 · Files, tools and your own data Lesson 10 of 15
The speech API and streaming and your first script
The platform offers a speech API that returns audio for a piece of text, and a streaming endpoint for live audio, which is how narration gets into an application rather than a download folder. You do not need this to finish the course, and you do not need it for a fresher job either — but an afternoon here is what turns "I have used ElevenLabs" into "I have built with it", which is a different sentence in an interview.
The concept
The platform offers a speech API that returns audio for a piece of text, and a streaming endpoint for live audio, which is how narration gets into an application rather than a download folder. The idea is simple: the same model you have been chatting with also answers a web request, so you can put it inside a script, a spreadsheet or a page. A key identifies you; a request sends the text; a response comes back as data.
The reason to try it once, even if you never build anything: it makes the chat version less mysterious. You see that the whole conversation is text in and text out, that your instructions are literally lines of a request, and that "the model" is one parameter among several.
A first call looks like this:
import requests
VOICE = "YOUR_VOICE_ID"
KEY = "YOUR_ELEVENLABS_KEY"
text = "This is a test of the narration pipeline. It should sound like a person."
r = requests.post(
f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE}",
headers={"xi-api-key": KEY, "Content-Type": "application/json"},
json={"text": text, "model_id": "eleven_multilingual_v2"},
)
open("narration.mp3", "wb").write(r.content)Common mistakes
The mistake is storing the API key in the script you push to a public repository. Keys belong in environment variables, and a key that has ever been public is a key to revoke.
Worked example
A script that turns a folder of article text files into audio files with one consistent voice is a realistic weekend project, and it is genuinely useful for anyone who commutes.
Your practice task
Get a key, run one request that works, and change one word in it to see the answer change. That is the whole of the first afternoon.
Do this before moving on. Reading a solution teaches the shape of it; typing it teaches you.
Key takeaway
The platform offers a speech API that returns audio for a piece of text, and a streaming endpoint for live audio, which is how narration gets into an application rather than a download folder.
Keep your place in this course
A free account saves which lessons you have finished and unlocks the certificate. The lesson itself stays free to read.
Create free account or sign inCourse complete
You finished every lesson.
Your certificate is ready, and the projects you built are the proof to attach to an application.
Almost there
15 lessons left of 15
Finish every lesson to unlock the certificate. Each one ends in a practice task — do them and the final project brief writes itself.
