examples/edge-functions/supabase/functions/elevenlabs-text-to-speech/README.md
Generate and stream speech through Supabase Edge Functions. Store speech in Supabase Storage and cache responses via built-in smart CDN.
After installing the Supabase CLI, run the following command to create a new Supabase project locally:
supabase init
You can configure the Supabase CLI to automatically generate a storage bucket by adding this configuration in the config.toml file:
[storage.buckets.audio]
public = false
file_size_limit = "50MiB"
allowed_mime_types = ["audio/mp3"]
objects_path = "./audio"
To use background tasks in Supabase Edge Functions when developing locally, you need to add the following configuration in the config.toml file:
[edge_runtime]
policy = "per_worker"
To run the function locally, run the following commands:
supabase start
Once the local Supabase stack is up and running, run the following command to start the function and observe the logs:
supabase functions serve
If you haven't already, create a new Supabase account at database.new and link the local project to your Supabase account:
supabase link
Once done, run the following command to deploy the function:
supabase functions deploy
Now that you have all your secrets set locally, you can run the following command to set the secrets in your Supabase project:
supabase secrets set --env-file supabase/functions/.env
The function is designed in a way that it can be used directly as a source for an <audio> element.
<audio
src="https://${SUPABASE_PROJECT_REF}.supabase.co/functions/v1/elevenlabs-text-to-speech?text=Hello%2C%20world!&voiceId=JBFqnCBsd6RMkjVDRZzb"
controls
/>
You can find an example frontend implementation in the complete code example on GitHub.
Navigate to http://127.0.0.1:54321/functions/v1/elevenlabs-text-to-speech?text=hello%20world.
Afterwards, navigate to http://127.0.0.1:54323/project/default/storage/buckets/audio to see the audio file in your local Supabase Storage bucket.
The function is designed in a way that it can be used directly as a source for an <audio> element.
<audio
src="https://${SUPABASE_PROJECT_REF}.supabase.co/functions/v1/elevenlabs-text-to-speech?text=Hello%2C%20world!&voiceId=JBFqnCBsd6RMkjVDRZzb"
controls
/>
You can find an example frontend implementation in the complete code example on GitHub.