Streaming and Caching Speech with Supabase

ElevenLabs · Beginner ·🛠️ AI Tools & Apps ·1y ago

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 AI Multilingual TTS Demo | ElevenLabs
AI Multilingual TTS Demo | ElevenLabs
ElevenLabs
2 Professional Voice Cloning Demo | ElevenLabs
Professional Voice Cloning Demo | ElevenLabs
ElevenLabs
3 Introducing: Projects
Introducing: Projects
ElevenLabs
4 ElevenLabs Dubbing Studio
ElevenLabs Dubbing Studio
ElevenLabs
5 ElevenLabs Speech to Speech
ElevenLabs Speech to Speech
ElevenLabs
6 Sound Effects are Coming Soon to ElevenLabs
Sound Effects are Coming Soon to ElevenLabs
ElevenLabs
7 It Started to Sing
It Started to Sing
ElevenLabs
8 It Started to Sing (Jazz)
It Started to Sing (Jazz)
ElevenLabs
9 Broke my Heart
Broke my Heart
ElevenLabs
10 My Love
My Love
ElevenLabs
11 ElevenLabs Dubbing API
ElevenLabs Dubbing API
ElevenLabs
12 ElevenLabs Audio Native
ElevenLabs Audio Native
ElevenLabs
13 Increasing reader engagement with Audio Native [June 2024 Webinar]
Increasing reader engagement with Audio Native [June 2024 Webinar]
ElevenLabs
14 ElevenLabs Text to Sound Effects API Demo
ElevenLabs Text to Sound Effects API Demo
ElevenLabs
15 ElevenLabs Voiceover Studio
ElevenLabs Voiceover Studio
ElevenLabs
16 ElevenLabs Speech to Speech Tutorial
ElevenLabs Speech to Speech Tutorial
ElevenLabs
17 ElevenLabs Voice Isolator API Demo
ElevenLabs Voice Isolator API Demo
ElevenLabs
18 ElevenLabs Turbo v2.5
ElevenLabs Turbo v2.5
ElevenLabs
19 ElevenLabs Reader App - Android
ElevenLabs Reader App - Android
ElevenLabs
20 ElevenLabs Impact Program
ElevenLabs Impact Program
ElevenLabs
21 We’ve reduced our pricing.
We’ve reduced our pricing.
ElevenLabs
22 Sound Effects Explore
Sound Effects Explore
ElevenLabs
23 Behind the Voice - Michael Marshall
Behind the Voice - Michael Marshall
ElevenLabs
24 X to Voice
X to Voice
ElevenLabs
25 Huberman Labs now Dubbing with ElevenLabs
Huberman Labs now Dubbing with ElevenLabs
ElevenLabs
26 GenFM, Now Playing on ElevenReader: Smart Podcasts Produced by Generative AI
GenFM, Now Playing on ElevenReader: Smart Podcasts Produced by Generative AI
ElevenLabs
27 Introducing ElevenLabs Conversational Agents
Introducing ElevenLabs Conversational Agents
ElevenLabs
28 Meet Flash
Meet Flash
ElevenLabs
29 Transforming media production with AI sound effects & dubbing
Transforming media production with AI sound effects & dubbing
ElevenLabs
30 ElevenLabs Conversational AI Webinar
ElevenLabs Conversational AI Webinar
ElevenLabs
31 ElevenLabs - Text to Speech, Dubbing, Sound Effects and more
ElevenLabs - Text to Speech, Dubbing, Sound Effects and more
ElevenLabs
32 Talk to Santa
Talk to Santa
ElevenLabs
33 Year in Review with special guest TIME's CTO Burhan Hamid
Year in Review with special guest TIME's CTO Burhan Hamid
ElevenLabs
34 Conversational AI Voice Agents that can issue refunds
Conversational AI Voice Agents that can issue refunds
ElevenLabs
35 Prenez une longueur d'avance avec ElevenLabs
Prenez une longueur d'avance avec ElevenLabs
ElevenLabs
36 Studio is now available to everyone, with new features (walkthrough)
Studio is now available to everyone, with new features (walkthrough)
ElevenLabs
37 Build Conversational AI agents with Gemini 2.0 Flash
Build Conversational AI agents with Gemini 2.0 Flash
ElevenLabs
38 Meet Alexis & El – Support Agents Handling 4,000 Calls a Day
Meet Alexis & El – Support Agents Handling 4,000 Calls a Day
ElevenLabs
39 Transform your Speech with ElevenLabs Voice Changer
Transform your Speech with ElevenLabs Voice Changer
ElevenLabs
40 Personalize conversational AI phone calls with Twilio
Personalize conversational AI phone calls with Twilio
ElevenLabs
41 Spotify is now accepting Audiobooks Narrated by ElevenLabs
Spotify is now accepting Audiobooks Narrated by ElevenLabs
ElevenLabs
42 Build Outbound AI Sales Agents
Build Outbound AI Sales Agents
ElevenLabs
43 Meet Scribe
Meet Scribe
ElevenLabs
44 Build a multilingual speech transcription bot with the ElevenLabs transcriber API
Build a multilingual speech transcription bot with the ElevenLabs transcriber API
ElevenLabs
Streaming and Caching Speech with Supabase
Streaming and Caching Speech with Supabase
ElevenLabs
46 Meet GibberLink, Conversational AI's secret language
Meet GibberLink, Conversational AI's secret language
ElevenLabs
47 Building a Personal AI Receptionist
Building a Personal AI Receptionist
ElevenLabs
48 Cross-platform AI Voice Agents with Expo React Native
Cross-platform AI Voice Agents with Expo React Native
ElevenLabs
49 Automatic Language Detection for Conversational AI
Automatic Language Detection for Conversational AI
ElevenLabs
50 Native Retrieval-Augmented Generation (RAG) in Conversational AI
Native Retrieval-Augmented Generation (RAG) in Conversational AI
ElevenLabs
51 Text to Bark from ElevenLabs
Text to Bark from ElevenLabs
ElevenLabs
52 Meet KUBI the Conversational Robot Barista
Meet KUBI the Conversational Robot Barista
ElevenLabs
53 Introducing the ElevenLabs MCP server
Introducing the ElevenLabs MCP server
ElevenLabs
54 Collect and analyze data with Conversational AI
Collect and analyze data with Conversational AI
ElevenLabs
55 Agent Transfer - Conversational AI
Agent Transfer - Conversational AI
ElevenLabs
56 Sound Effects are now available in Studio
Sound Effects are now available in Studio
ElevenLabs
57 How to Make your Professional Voice Clone.
How to Make your Professional Voice Clone.
ElevenLabs
58 Get unique AI Voiceovers in CapCut
Get unique AI Voiceovers in CapCut
ElevenLabs
59 Transfer to human - Conversational AI
Transfer to human - Conversational AI
ElevenLabs
60 Use HeyGen Avatar IV to Make AI Movie Characters
Use HeyGen Avatar IV to Make AI Movie Characters
ElevenLabs

This tutorial teaches you how to build an edge API to generate, stream, store, and cache speech using Supabase and ElevenLabs APIs. You will learn how to use Supabase Edge Functions and Storage, and integrate the ElevenLabs text-to-speech API.

Key Takeaways
  1. Create a Supabase project
  2. Set up Supabase Edge Functions
  3. Configure Supabase Storage
  4. Integrate ElevenLabs text-to-speech API
  5. Test the edge API locally
  6. Deploy the edge API
💡 Using edge computing and caching can significantly improve the performance and efficiency of speech generation and streaming applications.

Related Reads

📰
Price AI Downtime With an Exit-Option Ledger
Learn to calculate AI downtime costs using an exit-option ledger, considering variable work priorities and switching plans
Dev.to AI
📰
3 Essential Strategies for AI-Powered Productivity in Google Workspace (2026 Edition)
Boost productivity in Google Workspace with AI-powered strategies, essential for modern enterprise efficiency
Dev.to AI
📰
Unlock Peak Performance: How AI in Google Workspace is Redefining Enterprise Productivity in 2026
Learn how AI in Google Workspace boosts enterprise productivity in 2026 and why it's crucial for businesses to integrate AI into their core strategy
Dev.to AI
📰
The New Creative Partner: Why AI-Generated Content Feels More Human Than Ever
Learn how AI-generated content is becoming increasingly human-like and why it matters for creatives and businesses
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
Up next
Forget ChatGPT, This AI Actually Runs My Small Business | Claude Co-Work Review
MailerLite
Watch →