This is a Go client library for the ElevenLabs voice cloning and speech synthesis platform. It provides a basic interface for Go programs to interact with the ElevenLabs API.
Forked from: github.com/haguro/elevenlabs-go
go get github.com/clearlyip/elevenlabs-go
client := elevenlabs.NewClient(d.localContext, d.config.ApiKey, 1*time.Minute)
err := client.TextToSpeechInputStream(
d.InputChan, // chan string
d.ResponseChan, // chan StreamingOutputResponse
d.config.Voice, // Voice ID
d.config.Model, // TTS model
elevenlabs.TextToSpeechInputStreamingRequest{
Text: " ",
TryTriggerGeneration: true,
VoiceSettings: &elevenlabs.VoiceSettings{
Stability: d.config.ElevenlabsStability,
SimilarityBoost: d.config.ElevenlabsSimilarityBoost,
Style: d.config.ElevenlabsStyle,
},
},
elevenlabs.OutputFormat(d.codec))
if err != nil {
d.logger.Errorw("🧨 ElevenLabs: Got error", err)
continue
}
These are declared within the elevenlabs driver, for example: elevenlabs.StreamingOutputResponse
type StreamingOutputResponse struct {
Audio []byte `json:"audio"`
IsFinal bool `json:"isFinal"`
NormalizedAlignment StreamingAlignmentSegment `json:"normalizedAlignment"`
Alignment StreamingAlignmentSegment `json:"alignment"`
}
type StreamingAlignmentSegment struct {
CharStartTimesMs []int `json:"charStartTimesMs"`
CharDurationsMs []int `json:"charDurationsMs"`
Chars []string `json:"chars"`
}
Define a channel to handle these responses:
var FromElevenLabsChannel chan elevenlabs.StreamingOutputResponse
Create the channel and assign it:
FromElevenLabsChannel = make(chan elevenlabs.StreamingOutputResponse)
Watch for responses:
for {
select {
case <-d.localContext.Done():
d.log.Debug("ElevenLabs: Exiting output buffer handling loop via localContext.Done()")
return
case ttsMsg := <-FromElevenLabsChannel:
// handle the response
}