This is an Encore package for generating text-to-speech audio using ElevenLabs generative voice AI.
elevenlabs
package directory to your Encore application.go mod tidy
.You will need an API key from ElevenLabs to use this package. You can get one by signing up for a free account at https://elevenlabs.io/.
Once you have the API key, set it as an Encore secret using the name ElevenLabsAPIKey
:
$ encore secret set --type dev,prod,local,pr ElevenLabsAPIKey
Enter secret value: *****
Successfully updated development secret ElevenLabsAPIKey.
The elevenlabs
package contains the following endpoints:
ServeAudio generates audio from text and serves it as mpeg to the client.
// Making request to locally running backend...
const client = new Client(Local);
// or to a specific deployed environment
const client = new Client(Environment("staging"));
const resp = await client.elevenlabs.ServeAudio("POST", JSON.stringify({text}));
const url = window.URL.createObjectURL(await resp.blob()); //where value is the blob
const audio = new Audio();
audio.src = url;
await audio.play();
StreamAudio generates audio from text and streams it as mpeg to the client.
<audio controls>
<source src="http://localhost:4000/speech/stream" type="audio/mpeg"/>
Your browser does not support the audio element.
</audio>
DownloadAudio generates audio from text and saves the audio file as mp3 to disk.