No oficial elevenlabs.io (11.ai) Cliente de síntesis de voz
Esta biblioteca no está afiliada, ni asociada con once de ninguna manera.
La documentación oficial de API de Elevenlabs, sobre la cual se ha derivado este cliente, se puede encontrar aquí.
Este cliente GO proporciona una interfaz fácil para crear voces sintetizadas y realizar solicitudes de TTS (texto a voz) a ElevenLabs.io
Como requisito previo, ya debe tener una cuenta con ElevenLabs.io. Después de crear su cuenta, puede obtener su clave API desde aquí.
Para probar un ejemplo say ejemplo, ejecute:
go install github.com/taigrr/elevenlabs/cmd/say@latest
¡Establezca la variable de entorno XI_API_KEY y suplique algún texto para darle un giro!
Para usar esta biblioteca, cree un nuevo cliente y envíe una solicitud TTS a una voz. El siguiente bloque de código ilustra cómo se puede replicar el comando say/espeak, utilizando el punto final de transmisión. He optado por ir con el paquete Beep de Faiface, pero también puede guardar el archivo en un MP3 en el disco.
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
}El siguiente ejemplo demuestra cómo generar efectos de sonido utilizando la API de generación de sonido:
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 )
}