Streaming and Caching Speech with Supabase
Key Takeaways
This video tutorial demonstrates how to build an edge API using Supabase Edge Functions, Supabase Storage, and ElevenLabs text-to-speech API to generate, stream, store, and cache speech.
Full Transcript
today let's look at streaming and caching speech using superbase Edge functions and super base storage so let's have a look at the demo real quick so let's say we want to generate you know a bit of longer text uh into audio and we you know select a specific voice here Sarah and so you can now see that um we're making a request 11 Labs raises 180 Ma in series C funding to advance its AI audio technology and we can look at the timing here so you can see that and sound you know the request is not finished yet so it is streaming uh the response back so initially we're just waiting for the server so I'm running this locally here so there's a bit of overhead there but then once we get the speech streaming we kind of keep um you know streaming it in the background until it's finished also when we pause here you can see kind of the the buffer sort of coming in uh and streaming in and so this is great so basically the first time you know we're generating this um you know we want to generate it and then we want to save it to super base storage so say the next time that we're um generating the exact same text with the exact same voice 11 Labs raises we can now see that it's coming immediately from the CDN and we're not actually generating anything anymore and so that is exactly what we want to build today and we can leverage superbase Edge function and superbase storage which has a built-in smart CDN for this so let's have a look at the code so uh our front end here is just a nice little static side generated by lovable uh it's great love very much and so you can see here we're just using react and um initially we're just fetching all the voices here from the 11 laps API uh and putting them into our drop- down here so we can generate kind of the you know different voices that are available and then uh what you can see is we're you know just setting up kind of our react State status is here fetching the voices so once we have the voices and then you can see really the magic is happening here in the handle generate so all we're kind of doing is you know we're running locally here we're triggering our function which is called text to speech with a text parameter and a voice ID parameter and so let's have a look at the superbase function here that is making that happen this is our superbase function so we have the edge run time here uh our superbase client our 11 laps client and we're using uh an object hash uh library to generate a hash for um the parameters that we're taking in from from the API and so you can see here we have um a background task so uh one thing that we want to do here is that we want to immediately start streaming back the response you know as the speech is being generated immediately stream that back to the user and then in the background upload it to superbase storage so we just have an async method here um where we're passing in a readable stream and then you can see superbase storage and we're just uploading our audio here to superbase storage so we can see now if we open the local um superbase studio and we go to storage audio so we have two things that were generated here 11 Labs raises 180 MERS in series and so these are different voices 11 Labs raises 180 m and so there different hash so we're just naming our file with the hash of the request parameters and so once we have that uploaded that's great that's our Asing function here and so this is our request Handler so as we're setting the audio Source here we're setting the audio Source on our audio um element you can see that here so we have um once we have an audio Source we then um setting that into the source of our uh HTML audio element and so when that is happening we're making a request to our server and we're just getting out the parameters so specifically the text and the voice ID and so for the same text and the same voice ID we want to look up if we have um you know a cached an already generated audio file in superbase storage so what we're doing is just we're generating hash um over the request so the text and the voice ID parameter um and then what we're doing is we're looking up in superbase storage if we have a file for this hash and then create assigned URL for it and so if we already have a file what we can do is we can fetch that file and we can then simply return the response of that fetch request back to um you know our front end and so the great thing here is that superbas storage has built in smart CDN so we're basically just serving this from a global uh CDN which makes this really Snappy really fast um as you saw I think it was like you know obviously also it's St here locally on my machine so um it's on the edgiest edge it can be um okay great but so say we don't have it cashed already we want to generate it and so that's where we're making an API call to 11lbs and specifically here we're using the text to speech and we're using the stream method so we're passing on our voice ID our text um a specific MP3 format and the model ID and then what we get back as a response is uh a node stream so we can then uh chunk through the node stream create a new browser readable stream so that's what we're kind of using in Dino and so once we have that stream uh a really cool feature of this stream is that we can tea off the stream so you can think of it as you know like a like a branching off so we're basically cloning our stream which is a really cool feature here so now we can pass one part of the stream to our background function so we can start uploading you know in the background uh and the edge run time will just wait until that upload is finished but at the same time without you know blocking we want to immediately start returning the browser stream back to the user to the client so that immediately as we get um you know the initial part of the speech generated um get that streamed back to the user response and you know you can see really this is just a couple lines of code but by combining these Technologies you know 11 laps uh Speech generation with streaming and then super base Edge functions and superbase storage which has the smart CDN built in this you know becomes really powerful in building applications here and so now lastly we can say thanks for tuning in and we can maybe see what uh Roger sounds like all right let's generate that thanks for tuning in all right thanks for tuning in let us know what you want to learn next and I'll see you then bye-bye
Original Description
In this tutorial you will learn how to build an edge API to generate, stream, store, and cache speech using Supabase Edge Functions, Supabase Storage, and ElevenLabs text-to-speech API.
Try ElevenLabs: https://elevenlabs.io?utm_source=youtube&utm_medium=organic&utm_campaign=not_set&utm_content=streaming_and_caching_speech_with_supabase
- Find the cookbook: https://elevenlabs.io/docs/cookbooks/text-to-speech/streaming-and-caching-with-supabase
- FInd the code: https://github.com/elevenlabs/elevenlabs-examples/tree/main/examples/text-to-speech/supabase/stream-and-cache-storage
## Chapters
0:00 - Intro
0:10 - Speech Generation Demo
1:48 - Code Overview
3:42 - Testing locally with Supabase
4:05 - Reviewing the Edge Function code
7:44 - Testing the Code and Final Thoughts
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from ElevenLabs · ElevenLabs · 45 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
▶
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
AI Multilingual TTS Demo | ElevenLabs
ElevenLabs
Professional Voice Cloning Demo | ElevenLabs
ElevenLabs
Introducing: Projects
ElevenLabs
ElevenLabs Dubbing Studio
ElevenLabs
ElevenLabs Speech to Speech
ElevenLabs
Sound Effects are Coming Soon to ElevenLabs
ElevenLabs
It Started to Sing
ElevenLabs
It Started to Sing (Jazz)
ElevenLabs
Broke my Heart
ElevenLabs
My Love
ElevenLabs
ElevenLabs Dubbing API
ElevenLabs
ElevenLabs Audio Native
ElevenLabs
Increasing reader engagement with Audio Native [June 2024 Webinar]
ElevenLabs
ElevenLabs Text to Sound Effects API Demo
ElevenLabs
ElevenLabs Voiceover Studio
ElevenLabs
ElevenLabs Speech to Speech Tutorial
ElevenLabs
ElevenLabs Voice Isolator API Demo
ElevenLabs
ElevenLabs Turbo v2.5
ElevenLabs
ElevenLabs Reader App - Android
ElevenLabs
ElevenLabs Impact Program
ElevenLabs
We’ve reduced our pricing.
ElevenLabs
Sound Effects Explore
ElevenLabs
Behind the Voice - Michael Marshall
ElevenLabs
X to Voice
ElevenLabs
Huberman Labs now Dubbing with ElevenLabs
ElevenLabs
GenFM, Now Playing on ElevenReader: Smart Podcasts Produced by Generative AI
ElevenLabs
Introducing ElevenLabs Conversational Agents
ElevenLabs
Meet Flash
ElevenLabs
Transforming media production with AI sound effects & dubbing
ElevenLabs
ElevenLabs Conversational AI Webinar
ElevenLabs
ElevenLabs - Text to Speech, Dubbing, Sound Effects and more
ElevenLabs
Talk to Santa
ElevenLabs
Year in Review with special guest TIME's CTO Burhan Hamid
ElevenLabs
Conversational AI Voice Agents that can issue refunds
ElevenLabs
Prenez une longueur d'avance avec ElevenLabs
ElevenLabs
Studio is now available to everyone, with new features (walkthrough)
ElevenLabs
Build Conversational AI agents with Gemini 2.0 Flash
ElevenLabs
Meet Alexis & El – Support Agents Handling 4,000 Calls a Day
ElevenLabs
Transform your Speech with ElevenLabs Voice Changer
ElevenLabs
Personalize conversational AI phone calls with Twilio
ElevenLabs
Spotify is now accepting Audiobooks Narrated by ElevenLabs
ElevenLabs
Build Outbound AI Sales Agents
ElevenLabs
Meet Scribe
ElevenLabs
Build a multilingual speech transcription bot with the ElevenLabs transcriber API
ElevenLabs
Streaming and Caching Speech with Supabase
ElevenLabs
Meet GibberLink, Conversational AI's secret language
ElevenLabs
Building a Personal AI Receptionist
ElevenLabs
Cross-platform AI Voice Agents with Expo React Native
ElevenLabs
Automatic Language Detection for Conversational AI
ElevenLabs
Native Retrieval-Augmented Generation (RAG) in Conversational AI
ElevenLabs
Text to Bark from ElevenLabs
ElevenLabs
Meet KUBI the Conversational Robot Barista
ElevenLabs
Introducing the ElevenLabs MCP server
ElevenLabs
Collect and analyze data with Conversational AI
ElevenLabs
Agent Transfer - Conversational AI
ElevenLabs
Sound Effects are now available in Studio
ElevenLabs
How to Make your Professional Voice Clone.
ElevenLabs
Get unique AI Voiceovers in CapCut
ElevenLabs
Transfer to human - Conversational AI
ElevenLabs
Use HeyGen Avatar IV to Make AI Movie Characters
ElevenLabs
More on: AI Workflow Automation
View skill →Related Reads
📰
📰
📰
📰
Price AI Downtime With an Exit-Option Ledger
Dev.to AI
3 Essential Strategies for AI-Powered Productivity in Google Workspace (2026 Edition)
Dev.to AI
Unlock Peak Performance: How AI in Google Workspace is Redefining Enterprise Productivity in 2026
Dev.to AI
The New Creative Partner: Why AI-Generated Content Feels More Human Than Ever
Medium · AI
Chapters (6)
Intro
0:10
Speech Generation Demo
1:48
Code Overview
3:42
Testing locally with Supabase
4:05
Reviewing the Edge Function code
7:44
Testing the Code and Final Thoughts
🎓
Tutor Explanation
DeepCamp AI