Inofficial ElevenLabs.io (11.ai) Client de synthèse vocale
Cette bibliothèque n'est pas affiliée, ni associée à ElevenLabs.
La documentation officielle de l'API d'ElevenLabs, sur laquelle ce client a été dérivée, peut être trouvée ici.
Ce client Go fournit une interface facile à créer des voix synthétisées et à faire des demandes TTS (text-to-dispeophe) à ElevenLabs.io
En tant que condition préalable, vous devez déjà avoir un compte avec ElevenLabs.io. Après avoir créé votre compte, vous pouvez obtenir votre clé API à partir d'ici.
Pour tester un exemple say programme, exécutez:
go install github.com/taigrr/elevenlabs/cmd/say@latest
Définissez la variable d'environnement XI_API_KEY et tuysez-le du texte pour lui donner un tourbillon!
Pour utiliser cette bibliothèque, créez un nouveau client et envoyez une demande TTS à une voix. Le bloc de code suivant illustre comment on pourrait reproduire la commande Say / Espeak, en utilisant le point de terminaison de streaming. J'ai choisi d'aller avec le package bip de Faiface, mais vous pouvez également enregistrer le fichier sur un disque MP3.
package main
import (
"bufio"
"context"
"io"
"log"
"os"
"time"
"github.com/faiface/beep"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
"github.com/taigrr/elevenlabs/client"
"github.com/taigrr/elevenlabs/client/types"
)
func main () {
ctx := context . Background ()
// load in an API key to create a client
client := client . New ( os . Getenv ( "XI_API_KEY" ))
// fetch a list of voice IDs from elevenlabs
ids , err := client . GetVoiceIDs ( ctx )
if err != nil {
panic ( err )
}
// prepare a pipe for streaming audio directly to beep
pipeReader , pipeWriter := io . Pipe ()
reader := bufio . NewReader ( os . Stdin )
text , _ := reader . ReadString ( 'n' )
go func () {
// stream audio from elevenlabs using the first voice we found
err = client . TTSStream ( ctx , pipeWriter , text , ids [ 0 ], types. SynthesisOptions { Stability : 0.75 , SimilarityBoost : 0.75 , Style : 0.0 , UseSpeakerBoost : true })
if err != nil {
panic ( err )
}
pipeWriter . Close ()
}()
// decode and prepare the streaming mp3 as it comes through
streamer , format , err := mp3 . Decode ( pipeReader )
if err != nil {
log . Fatal ( err )
}
defer streamer . Close ()
speaker . Init ( format . SampleRate , format . SampleRate . N ( time . Second / 10 ))
done := make ( chan bool )
// play the audio
speaker . Play ( beep . Seq ( streamer , beep . Callback ( func () {
done <- true
})))
<- done
}L'exemple suivant montre comment générer des effets sonores à l'aide de l'API de génération de son:
package main
import (
"context"
"os"
"github.com/taigrr/elevenlabs/client"
)
func main () {
ctx := context . Background ()
// Create a new client with your API key
client := client . New ( os . Getenv ( "XI_API_KEY" ))
// Generate a sound effect and save it to a file
f , err := os . Create ( "footsteps.mp3" )
if err != nil {
panic ( err )
}
defer f . Close ()
// Basic usage (using default duration and prompt influence)
err = client . SoundGenerationWriter ( ctx , f , "footsteps on wooden floor" , 0 , 0 )
if err != nil {
panic ( err )
}
// Advanced usage with custom duration and prompt influence
audio , err := client . SoundGeneration (
ctx ,
"heavy rain on a tin roof" ,
5.0 , // Set duration to 5 seconds
0.5 , // Set prompt influence to 0.5
)
if err != nil {
panic ( err )
}
os . WriteFile ( "rain.mp3" , audio , 0644 )
}