Documentation
¶
Overview ¶
Package elevenlabs provides a Go client for the ElevenLabs API.
The client wraps the ogen-generated API client with a higher-level interface that handles authentication and provides convenient methods for common operations.
Index ¶
- Constants
- Variables
- func GetAXErrorCode(err error) (string, bool)
- func IsAXError(err error, code string) bool
- func IsForbiddenError(err error) bool
- func IsNotFoundError(err error) bool
- func IsRateLimitError(err error) bool
- func IsUnauthorizedError(err error) bool
- type APIError
- type Client
- func (c *Client) API() *api.Client
- func (c *Client) APIKey() string
- func (c *Client) Account() *account.Service
- func (c *Client) Agents() *agents.Service
- func (c *Client) Audio() *audio.Service
- func (c *Client) BaseURL() string
- func (c *Client) Content() *content.Service
- func (c *Client) Realtime() *realtime.Service
- func (c *Client) STT() *stt.Service
- func (c *Client) TTS() *tts.Service
- func (c *Client) Telephony() *telephony.Service
- func (c *Client) Voice() *voice.Service
- type Option
- type ValidationError
- type VoiceSettings
- func DefaultVoiceSettings() *VoiceSettings
- func VoiceSettingsForAudiobook() *VoiceSettings
- func VoiceSettingsForCoursera() *VoiceSettings
- func VoiceSettingsForEdX() *VoiceSettings
- func VoiceSettingsForInstagram() *VoiceSettings
- func VoiceSettingsForPodcast() *VoiceSettings
- func VoiceSettingsForTikTok() *VoiceSettings
- func VoiceSettingsForUdemy() *VoiceSettings
- func VoiceSettingsForYouTube() *VoiceSettings
Constants ¶
const DefaultBaseURL = "https://api.elevenlabs.io"
DefaultBaseURL is the default ElevenLabs API base URL.
const DefaultModelID = "eleven_multilingual_v2"
DefaultModelID is the recommended model for text-to-speech.
const Version = "0.13.0"
Version is the SDK version.
Variables ¶
var ( // ErrNoAPIKey is returned when no API key is provided. ErrNoAPIKey = errors.New("elevenlabs: API key is required") // ErrEmptyText is returned when text is empty. ErrEmptyText = errors.New("elevenlabs: text cannot be empty") // ErrEmptyVoiceID is returned when voice ID is empty. ErrEmptyVoiceID = errors.New("elevenlabs: voice ID is required") // ErrInvalidStability is returned when stability is out of range. ErrInvalidStability = errors.New("elevenlabs: stability must be between 0.0 and 1.0") // ErrInvalidSimilarityBoost is returned when similarity_boost is out of range. ErrInvalidSimilarityBoost = errors.New("elevenlabs: similarity_boost must be between 0.0 and 1.0") // ErrInvalidStyle is returned when style is out of range. ErrInvalidStyle = errors.New("elevenlabs: style must be between 0.0 and 1.0") // ErrInvalidSpeed is returned when speed is out of range. ErrInvalidSpeed = errors.New("elevenlabs: speed must be between 0.25 and 4.0") )
Common errors
Functions ¶
func GetAXErrorCode ¶ added in v0.10.0
GetAXErrorCode extracts the AX error code from any error. Returns the error code and true if found, empty string and false otherwise.
func IsAXError ¶ added in v0.10.0
IsAXError checks if an error contains a specific AX error code. This works with any error type by first trying to parse it as an APIError.
Usage:
if IsAXError(err, ax.ErrDocumentNotFound) {
// Handle document not found
}
func IsForbiddenError ¶
IsForbiddenError returns true if the error is a 403 Forbidden error.
func IsNotFoundError ¶
IsNotFoundError returns true if the error is a 404 Not Found error.
func IsRateLimitError ¶
IsRateLimitError returns true if the error is a 429 Too Many Requests error.
func IsUnauthorizedError ¶
IsUnauthorizedError returns true if the error is a 401 Unauthorized error.
Types ¶
type APIError ¶
APIError represents an error returned by the ElevenLabs API.
func ParseAPIError ¶
ParseAPIError extracts API error details from an error returned by the SDK. It handles ogen's UnexpectedStatusCodeError and parses the response body to extract the ElevenLabs error message.
Usage:
resp, err := client.TextToSpeech().Generate(ctx, req)
if err != nil {
if apiErr := elevenlabs.ParseAPIError(err); apiErr != nil {
fmt.Printf("Status: %d, Message: %s\n", apiErr.StatusCode, apiErr.Message)
}
log.Fatal(err)
}
func (*APIError) AXErrorCode ¶ added in v0.10.0
AXErrorCode extracts the AX error code from the API error, if present. Returns the error code constant (e.g., ax.ErrDocumentNotFound) and true if found. Use this for machine-readable error handling:
if apiErr := ParseAPIError(err); apiErr != nil {
if code, ok := apiErr.AXErrorCode(); ok {
switch code {
case ax.ErrDocumentNotFound:
// Handle document not found
case ax.ErrNeedsAuthorization:
// Handle auth required
}
}
}
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the main ElevenLabs client for interacting with the API.
func (*Client) API ¶
API returns the underlying ogen-generated API client for advanced usage. Use this when you need access to API endpoints not covered by the high-level wrapper methods.
func (*Client) Account ¶ added in v0.13.0
Account returns the account management service. This includes user info, models, history, and pronunciation dictionaries.
func (*Client) Agents ¶ added in v0.12.0
Agents returns the ElevenAgents (Conversational AI) service. This includes agent management, conversations, knowledge base, testing, and batch calling.
func (*Client) Audio ¶ added in v0.13.0
Audio returns the audio processing service. This includes audio isolation, forced alignment, and sound effects generation.
func (*Client) Content ¶ added in v0.13.0
Content returns the content generation service. This includes music generation, dubbing, and Studio projects.
func (*Client) Realtime ¶ added in v0.13.0
Realtime returns the real-time streaming service. This includes WebSocket-based TTS and STT connections.
func (*Client) TTS ¶ added in v0.13.0
TTS returns the text-to-speech service. This includes TTS generation, speech-to-speech conversion, and dialogue generation.
type Option ¶
type Option func(*clientOptions)
Option is a functional option for configuring the Client.
func WithAPIKey ¶
WithAPIKey sets the API key for authentication.
func WithHTTPClient ¶
WithHTTPClient sets a custom HTTP client.
func WithTimeout ¶
WithTimeout sets the request timeout.
type ValidationError ¶
ValidationError represents a validation error.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.
type VoiceSettings ¶
type VoiceSettings struct {
// Stability determines how stable the voice is (0.0 to 1.0).
// Lower values introduce broader emotional range.
Stability float64
// SimilarityBoost determines how closely the AI should adhere to
// the original voice (0.0 to 1.0).
SimilarityBoost float64
// Style determines the style exaggeration (0.0 to 1.0).
// Higher values amplify the original speaker's style.
Style float64
// Speed adjusts the speed of the voice (0.25 to 4.0).
// 1.0 is the default speed.
Speed float64
// UseSpeakerBoost boosts similarity to the original speaker.
UseSpeakerBoost bool
}
VoiceSettings represents voice configuration options for speech synthesis.
func DefaultVoiceSettings ¶
func DefaultVoiceSettings() *VoiceSettings
DefaultVoiceSettings returns sensible default voice settings.
func VoiceSettingsForAudiobook ¶
func VoiceSettingsForAudiobook() *VoiceSettings
VoiceSettingsForAudiobook returns settings tuned for audiobook narration. Clear, consistent, easy to listen to for extended periods.
func VoiceSettingsForCoursera ¶
func VoiceSettingsForCoursera() *VoiceSettings
VoiceSettingsForCoursera returns settings tuned for Coursera courses. Slightly expressive, engaging for mixed media content.
func VoiceSettingsForEdX ¶
func VoiceSettingsForEdX() *VoiceSettings
VoiceSettingsForEdX returns settings tuned for edX courses. Very stable, highly intelligible, slightly faster for dense academic content.
func VoiceSettingsForInstagram ¶
func VoiceSettingsForInstagram() *VoiceSettings
VoiceSettingsForInstagram returns settings tuned for Instagram content. Energetic but polished, suitable for brand content.
func VoiceSettingsForPodcast ¶
func VoiceSettingsForPodcast() *VoiceSettings
VoiceSettingsForPodcast returns settings tuned for podcast content. Natural conversational tone for long-form audio content.
func VoiceSettingsForTikTok ¶
func VoiceSettingsForTikTok() *VoiceSettings
VoiceSettingsForTikTok returns settings tuned for TikTok content. Designed for immediate engagement in the first 1-3 seconds.
func VoiceSettingsForUdemy ¶
func VoiceSettingsForUdemy() *VoiceSettings
VoiceSettingsForUdemy returns settings tuned for Udemy courses. Neutral, clear, consistent, safe for long lectures.
func VoiceSettingsForYouTube ¶
func VoiceSettingsForYouTube() *VoiceSettings
VoiceSettingsForYouTube returns settings tuned for YouTube content. Designed to hold attention for 5-20 minutes without sounding robotic or theatrical.
func (*VoiceSettings) Validate ¶
func (vs *VoiceSettings) Validate() error
Validate checks if the voice settings are within valid ranges.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package account provides user account, models, history, and pronunciation dictionary services.
|
Package account provides user account, models, history, and pronunciation dictionary services. |
|
Package agents provides ElevenAgents (Conversational AI) services.
|
Package agents provides ElevenAgents (Conversational AI) services. |
|
Package audio provides audio processing services including isolation, alignment, and sound effects.
|
Package audio provides audio processing services including isolation, alignment, and sound effects. |
|
Package ax provides Agent Experience (AX) metadata for the ElevenLabs API.
|
Package ax provides Agent Experience (AX) metadata for the ElevenLabs API. |
|
cmd
|
|
|
elevenlabs
command
Command elevenlabs is the CLI for ElevenLabs text-to-speech services.
|
Command elevenlabs is the CLI for ElevenLabs text-to-speech services. |
|
openapi-convert
command
Command openapi-convert converts OpenAPI 3.1 specs to 3.0.3 for ogen compatibility.
|
Command openapi-convert converts OpenAPI 3.1 specs to 3.0.3 for ogen compatibility. |
|
Package content provides content generation services including music, dubbing, and projects.
|
Package content provides content generation services including music, dubbing, and projects. |
|
examples
|
|
|
ax-error-handling
command
Example demonstrating AX (Agent Experience) error handling
|
Example demonstrating AX (Agent Experience) error handling |
|
basic
command
Example basic shows how to use the ElevenLabs SDK for common operations.
|
Example basic shows how to use the ElevenLabs SDK for common operations. |
|
retryhttp
command
Example demonstrating retry middleware with ElevenLabs client.
|
Example demonstrating retry middleware with ElevenLabs client. |
|
simple
command
|
|
|
speech-to-speech
command
Example: Speech-to-Speech - Voice conversion
|
Example: Speech-to-Speech - Voice conversion |
|
ttsscript
command
Example: Using ttsscript to generate multilingual TTS audio
|
Example: Using ttsscript to generate multilingual TTS audio |
|
twilio
command
Example: Twilio Integration - Phone call handling
|
Example: Twilio Integration - Phone call handling |
|
websocket-stt
command
Example: WebSocket STT - Real-time speech-to-text streaming
|
Example: WebSocket STT - Real-time speech-to-text streaming |
|
websocket-tts
command
Example: WebSocket TTS - Real-time text-to-speech streaming
|
Example: WebSocket TTS - Real-time text-to-speech streaming |
|
internal
|
|
|
api
Code generated by ogen, DO NOT EDIT.
|
Code generated by ogen, DO NOT EDIT. |
|
Package omnivoice provides OmniVoice integration for elevenlabs-go.
|
Package omnivoice provides OmniVoice integration for elevenlabs-go. |
|
agent
Package agent provides an OmniVoice Agent provider implementation using ElevenLabs.
|
Package agent provides an OmniVoice Agent provider implementation using ElevenLabs. |
|
stt
Package stt provides an OmniVoice STT provider implementation using ElevenLabs.
|
Package stt provides an OmniVoice STT provider implementation using ElevenLabs. |
|
tts
Package tts provides an OmniVoice TTS provider implementation using ElevenLabs.
|
Package tts provides an OmniVoice TTS provider implementation using ElevenLabs. |
|
Package realtime provides WebSocket-based real-time TTS and STT services.
|
Package realtime provides WebSocket-based real-time TTS and STT services. |
|
Package stt provides speech-to-text transcription services.
|
Package stt provides speech-to-text transcription services. |
|
Package telephony provides phone integration services for Twilio and SIP.
|
Package telephony provides phone integration services for Twilio and SIP. |
|
Package tts provides text-to-speech, speech-to-speech, and dialogue generation services.
|
Package tts provides text-to-speech, speech-to-speech, and dialogue generation services. |
|
Package ttsconfig provides configuration types and utilities for ElevenLabs TTS.
|
Package ttsconfig provides configuration types and utilities for ElevenLabs TTS. |
|
Package ttsscript provides a structured format for authoring multilingual TTS (Text-to-Speech) scripts that can be compiled to various output formats.
|
Package ttsscript provides a structured format for authoring multilingual TTS (Text-to-Speech) scripts that can be compiled to various output formats. |
|
Package voice provides voice management and design services.
|
Package voice provides voice management and design services. |
|
Package voices provides reference information for ElevenLabs voices.
|
Package voices provides reference information for ElevenLabs voices. |