Maintainers
Pricing
Enterprise
More
More
Documentation
Try Live
Rankings
Install
Blog
Docs7
Ask
New
Add Docs
ElevenLabs
https://github.com/taigrr/elevenlabs
Admin
ElevenLabs Artificial Voice Synthesis Client
Tokens:
814
Snippets:
2
Trust Score:
9.4
Update:
1 year ago
Context
Chat
Benchmark
0
Latest
Show doc for...
Code
Info
Show Results
Tokens:
Raw
Copy
Link
Tokens:
Raw
Copy
Link
### Generate sound effects using ElevenLabs Sound Generation API in Go Source: https://github.com/taigrr/elevenlabs/blob/master/README.md This Go example demonstrates how to use the ElevenLabs client to generate sound effects. It illustrates both basic usage for saving a sound to a file and advanced usage for generating audio with custom duration and prompt influence. An API key is required for client initialization. ```Go 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) } ``` -------------------------------- ### Perform Text-to-Speech (TTS) streaming with ElevenLabs Go client Source: https://github.com/taigrr/elevenlabs/blob/master/README.md This Go example demonstrates how to use the ElevenLabs client to perform text-to-speech streaming. It fetches available voice IDs, streams audio from ElevenLabs based on user input, and plays it using the gopxl/beep package for real-time audio playback. An API key is required for client initialization. ```Go package main import ( "bufio" "context" "io" "log" "os" "time" "github.com/gopxl/beep/v2" "github.com/gopxl/beep/v2/mp3" "github.com/gopxl/beep/v2/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 } ```