Categorygithub.com/clearlyip/elevenlabs-go
modulepackage
1.6.5
Repository: https://github.com/clearlyip/elevenlabs-go.git
Documentation: pkg.go.dev

# README

elevenlabs-go

Go version License Tests codecov Go Report Card Go Reference

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

Installation

go get github.com/clearlyip/elevenlabs-go

Websocket doInputStreamingRequest (mod Jan 2025)

Using (Consumer side)

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
		}

Responses

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
}

# Packages

No description provided by the author

# Functions

AddVoice calls the AddVoice method on the default client.
DeleteHistoryItem calls the DeleteHistoryItem method on the default client.
DeleteSample calls the DeleteSample method on the default client.
DeleteVoice calls the DeleteVoice method on the default client.
DownloadHistoryAudio calls the DownloadHistoryAudio method on the default client.
EditVoice calls the EditVoice method on the default client.
EditVoiceSettings calls the EditVoiceSettings method on the default client.
GetDefaultVoiceSettings calls the GetDefaultVoiceSettings method on the default client.
GetHistory calls the GetHistory method on the default client.
GetHistoryItem calls the GetHistoryItem method on the default client.
GetHistoryItemAudio calls the GetHistoryItemAudio method on the default client.
GetModels calls the GetModels method on the default client.
GetSampleAudio calls the GetSampleAudio method on the default client.
GetSubscription calls the GetSubscription method on the default client.
GetUser calls the GetUser method on the default client.
GetVoice calls the GetVoice method on the default client.
GetVoices calls the GetVoices method on the default client.
GetVoiceSettings calls the GetVoiceSettings method on the default client.
LatencyOptimizations returns a QueryFunc that sets the http query 'optimize_streaming_latency' to a certain value.
NewClient creates and returns a new Client object with provided settings.
OutputFormat returns a QueryFunc that sets the http query 'output_format' to a certain value.
PageSize returns a QueryFunc that sets the http query 'page_size' to a given value.
SetAPIKey sets the API key for the default client.
SetTimeout sets the timeout duration for the default client.
StartAfter returns a QueryFunc that sets the http query 'start_after_history_item_id' to a given item ID.
TextToSpeech calls the TextToSpeech method on the default client.
TextToSpeechInputStream calls the TextToSpeechInputStream method on the default client.
TextToSpeechStream calls the TextToSpeechStream method on the default client.
WithSettings returns a QueryFunc that sets the http query 'with_settings' to true.

# Structs

No description provided by the author
No description provided by the author
APIError represents an error response from the API.
APIErrorDetail contains detailed information about an APIError.
Client represents an API client that can be used to make calls to the Elevenlabs API.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ValidationError represents a request validation error response from the API.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

NextHistoryPageFunc represent functions that can be used to access subsequent history pages.
QueryFunc represents the type of functions that sets certain query string to a given or certain value.
No description provided by the author