elevenlabs

package
v0.0.0-...-06d4644 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 17, 2025 License: MIT Imports: 6 Imported by: 0

README

ElevenLabs Generative AI Text-to-Speech

This is an Encore package for generating text-to-speech audio using ElevenLabs generative voice AI.

Installation

  1. Copy over the elevenlabs package directory to your Encore application.
  2. Sync your project dependencies by running go mod tidy.

ElevenLabs API Key

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.

Endpoints

The elevenlabs package contains the following endpoints:

elevenlabs.ServeAudio

ServeAudio generates audio from text and serves it as mpeg to the client.

Frontend example usage
// 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();
elevenlabs.StreamAudio

StreamAudio generates audio from text and streams it as mpeg to the client.

Frontend example usage
<audio controls>
  <source src="http://localhost:4000/speech/stream" type="audio/mpeg"/>
  Your browser does not support the audio element.
</audio>
elevenlabs.DownloadAudio

DownloadAudio generates audio from text and saves the audio file as mp3 to disk.

Learn More

Documentation

Overview

Package elevenlabs is used for handling communication with generative voice AI from https://elevenlabs.io/

Index

Constants

View Source
const MODEL_ID = "eleven_multilingual_v2" // AI models described here: https://docs.elevenlabs.io/speech-synthesis/models
View Source
const VOICE_ID = "pNInz6obpgDQGcFmaJgB" // Get other voice IDs here: https://docs.elevenlabs.io/api-reference/voices

Variables

This section is empty.

Functions

func DownloadAudio

func DownloadAudio(ctx context.Context, params *SpeechRequest) error

DownloadAudio generates audio from text and saves the audio file as mp3 to disk.

func ServeAudio

func ServeAudio(w http.ResponseWriter, req *http.Request)

ServeAudio generates audio from text and serves it as mpeg to the client.

func StreamAudio

func StreamAudio(w http.ResponseWriter, req *http.Request)

StreamAudio generates audio from text and streams it as mpeg to the client.

Types

type SpeechRequest

type SpeechRequest struct {
	Text string `json:"text"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL