Documentation
¶
Overview ¶
Package elevenlabs provides a small Go client for the ElevenLabs API.
Index ¶
- type APIError
- type Client
- func (c *Client) ConnectRealtimeTranscript(ctx context.Context, in RealtimeTranscriptRequest) (*RealtimeTranscriptSession, error)
- func (c *Client) CreateTranscript(ctx context.Context, in CreateTranscriptRequest) (*Transcript, error)
- func (c *Client) CreateTranscriptWithResponse(ctx context.Context, in CreateTranscriptRequest) (*Response[*Transcript], error)
- func (c *Client) DeleteTranscript(ctx context.Context, id string) error
- func (c *Client) DeleteTranscriptWithResponse(ctx context.Context, id string) (*Response[any], error)
- func (c *Client) GetTranscript(ctx context.Context, id string) (*Transcript, error)
- func (c *Client) GetTranscriptWithResponse(ctx context.Context, id string) (*Response[*Transcript], error)
- func (c *Client) GetUser(ctx context.Context) (*User, error)
- func (c *Client) GetUserWithResponse(ctx context.Context) (*Response[*User], error)
- func (c *Client) ListModels(ctx context.Context) ([]Model, error)
- func (c *Client) ListModelsWithResponse(ctx context.Context) (*Response[[]Model], error)
- func (c *Client) SubmitTranscriptWebhook(ctx context.Context, in CreateTranscriptRequest) (*TranscriptWebhookResponse, error)
- func (c *Client) SubmitTranscriptWebhookWithResponse(ctx context.Context, in CreateTranscriptRequest) (*Response[*TranscriptWebhookResponse], error)
- type ClientOption
- type CreateTranscriptRequest
- type DetectedEntity
- type File
- type Model
- type ModelLanguage
- type ModelRates
- type RawResponse
- type RealtimeAudioChunk
- type RealtimeTranscriptConfig
- type RealtimeTranscriptEvent
- type RealtimeTranscriptRequest
- type RealtimeTranscriptSession
- type RealtimeTranscriptWord
- type Response
- type RetryConfig
- type Transcript
- type TranscriptAdditionalFormat
- type TranscriptAdditionalFormatOptions
- type TranscriptCharacter
- type TranscriptWebhookResponse
- type TranscriptWord
- type UploadProgress
- type User
- type UserInvoice
- type UserSubscription
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct {
StatusCode int
Status string
Message string
Body []byte
ProviderType string
ProviderCode string
ProviderStatus string
ProviderMessage string
RequestID string
TraceID string
RetryAfter string
Validation []ValidationError
RawResponse RawResponse
}
APIError is returned when the ElevenLabs API responds with a non-2xx status.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an ElevenLabs API client.
func NewClient ¶
func NewClient(apiKey string, opts ...ClientOption) *Client
NewClient creates a Client that authenticates with apiKey.
func (*Client) ConnectRealtimeTranscript ¶
func (c *Client) ConnectRealtimeTranscript(ctx context.Context, in RealtimeTranscriptRequest) (*RealtimeTranscriptSession, error)
ConnectRealtimeTranscript opens a realtime speech-to-text WebSocket session.
func (*Client) CreateTranscript ¶
func (c *Client) CreateTranscript(ctx context.Context, in CreateTranscriptRequest) (*Transcript, error)
CreateTranscript transcribes an audio or video file.
func (*Client) CreateTranscriptWithResponse ¶
func (c *Client) CreateTranscriptWithResponse(ctx context.Context, in CreateTranscriptRequest) (*Response[*Transcript], error)
CreateTranscriptWithResponse transcribes an audio or video file and returns HTTP response metadata.
func (*Client) DeleteTranscript ¶
DeleteTranscript deletes a previously generated transcript by ID.
func (*Client) DeleteTranscriptWithResponse ¶
func (c *Client) DeleteTranscriptWithResponse(ctx context.Context, id string) (*Response[any], error)
DeleteTranscriptWithResponse deletes a previously generated transcript by ID and returns HTTP response metadata.
func (*Client) GetTranscript ¶
GetTranscript retrieves a previously generated transcript by ID.
func (*Client) GetTranscriptWithResponse ¶
func (c *Client) GetTranscriptWithResponse(ctx context.Context, id string) (*Response[*Transcript], error)
GetTranscriptWithResponse retrieves a previously generated transcript by ID and returns HTTP response metadata.
func (*Client) GetUserWithResponse ¶
GetUserWithResponse gets information about the authenticated user and returns HTTP response metadata.
func (*Client) ListModels ¶
ListModels gets the list of available models.
func (*Client) ListModelsWithResponse ¶
ListModelsWithResponse gets the list of available models and returns HTTP response metadata.
func (*Client) SubmitTranscriptWebhook ¶
func (c *Client) SubmitTranscriptWebhook(ctx context.Context, in CreateTranscriptRequest) (*TranscriptWebhookResponse, error)
SubmitTranscriptWebhook submits a transcript request for asynchronous webhook processing.
func (*Client) SubmitTranscriptWebhookWithResponse ¶
func (c *Client) SubmitTranscriptWebhookWithResponse(ctx context.Context, in CreateTranscriptRequest) (*Response[*TranscriptWebhookResponse], error)
SubmitTranscriptWebhookWithResponse submits a transcript request for asynchronous webhook processing and returns HTTP response metadata.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client.
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL overrides the ElevenLabs API base URL.
This is primarily useful for tests.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient overrides the HTTP client used for requests.
func WithRetryConfig ¶
func WithRetryConfig(cfg RetryConfig) ClientOption
WithRetryConfig overrides the retry policy used for replayable requests.
type CreateTranscriptRequest ¶
type CreateTranscriptRequest struct {
ModelID string
File *File
SourceURL string
CloudStorageURL string
EnableLogging *bool
LanguageCode string
TimestampsGranularity string
AdditionalFormats []TranscriptAdditionalFormatOptions
Diarize *bool
DiarizationThreshold *float64
NumSpeakers int
TagAudioEvents *bool
NoVerbatim *bool
Webhook *bool
WebhookID string
WebhookMetadata map[string]any
FileFormat string
Temperature *float64
Seed *int
UseMultiChannel *bool
MultichannelOutputStyle string
EntityDetection []string
UseSpeakerLibrary *bool
DetectSpeakerRoles *bool
EntityRedaction []string
EntityRedactionMode string
Keyterms []string
ExtraFormFields map[string][]string
OnUploadProgress func(UploadProgress)
}
CreateTranscriptRequest contains parameters for creating a speech-to-text transcript.
type DetectedEntity ¶
type DetectedEntity struct {
Text string `json:"text"`
EntityType string `json:"entity_type"`
StartChar int `json:"start_char"`
EndChar int `json:"end_char"`
}
DetectedEntity is an entity detected in a transcript.
type File ¶
type File struct {
Name string
Reader io.Reader
// SizeBytes is the total upload size reported in progress callbacks. When
// it is not positive, the client attempts to infer the size from Reader.
SizeBytes int64
}
File is a file upload for multipart API requests.
type Model ¶
type Model struct {
ModelID string `json:"model_id"`
Name string `json:"name,omitempty"`
CanBeFinetuned bool `json:"can_be_finetuned,omitempty"`
CanDoTextToSpeech bool `json:"can_do_text_to_speech,omitempty"`
CanDoVoiceConversion bool `json:"can_do_voice_conversion,omitempty"`
CanUseStyle bool `json:"can_use_style,omitempty"`
CanUseSpeakerBoost bool `json:"can_use_speaker_boost,omitempty"`
ServesProVoices bool `json:"serves_pro_voices,omitempty"`
TokenCostFactor float64 `json:"token_cost_factor,omitempty"`
Description string `json:"description,omitempty"`
RequiresAlphaAccess bool `json:"requires_alpha_access,omitempty"`
MaxCharactersRequestFreeUser int `json:"max_characters_request_free_user,omitempty"`
MaxCharactersRequestSubscribedUser int `json:"max_characters_request_subscribed_user,omitempty"`
MaximumTextLengthPerRequest int `json:"maximum_text_length_per_request,omitempty"`
Languages []ModelLanguage `json:"languages,omitempty"`
ModelRates *ModelRates `json:"model_rates,omitempty"`
ConcurrencyGroup string `json:"concurrency_group,omitempty"`
}
Model contains metadata for an ElevenLabs model.
type ModelLanguage ¶
ModelLanguage contains language metadata supported by a model.
type ModelRates ¶
type ModelRates struct {
CharacterCostMultiplier float64 `json:"character_cost_multiplier"`
CostDiscountMultiplier float64 `json:"cost_discount_multiplier,omitempty"`
}
ModelRates contains billing rate metadata for a model.
type RawResponse ¶
RawResponse contains HTTP response metadata.
It intentionally does not include the response body.
type RealtimeAudioChunk ¶
type RealtimeAudioChunk struct {
Audio []byte
AudioBase64 string
Commit bool
SampleRate int
PreviousText string
}
RealtimeAudioChunk is an audio chunk sent to a realtime transcription session.
type RealtimeTranscriptConfig ¶
type RealtimeTranscriptConfig struct {
SampleRate int `json:"sample_rate,omitempty"`
AudioFormat string `json:"audio_format,omitempty"`
LanguageCode string `json:"language_code,omitempty"`
CommitStrategy string `json:"commit_strategy,omitempty"`
VADSilenceThresholdSecs float64 `json:"vad_silence_threshold_secs,omitempty"`
VADThreshold float64 `json:"vad_threshold,omitempty"`
MinSpeechDurationMS int `json:"min_speech_duration_ms,omitempty"`
MinSilenceDurationMS int `json:"min_silence_duration_ms,omitempty"`
ModelID string `json:"model_id,omitempty"`
EnableLogging bool `json:"enable_logging,omitempty"`
IncludeTimestamps bool `json:"include_timestamps,omitempty"`
IncludeLanguageDetection bool `json:"include_language_detection,omitempty"`
Keyterms []string `json:"keyterms,omitempty"`
NoVerbatim bool `json:"no_verbatim,omitempty"`
}
RealtimeTranscriptConfig describes the started realtime transcription session.
type RealtimeTranscriptEvent ¶
type RealtimeTranscriptEvent struct {
MessageType string `json:"message_type"`
SessionID string `json:"session_id,omitempty"`
Config RealtimeTranscriptConfig `json:"config,omitempty"`
Text string `json:"text,omitempty"`
LanguageCode string `json:"language_code,omitempty"`
Words []RealtimeTranscriptWord `json:"words,omitempty"`
Error string `json:"error,omitempty"`
}
RealtimeTranscriptEvent is a JSON event received from a realtime speech-to-text session.
type RealtimeTranscriptRequest ¶
type RealtimeTranscriptRequest struct {
ModelID string
Token string
IncludeTimestamps *bool
IncludeLanguageDetection *bool
AudioFormat string
LanguageCode string
CommitStrategy string
Keyterms []string
NoVerbatim *bool
VADSilenceThresholdSecs *float64
VADThreshold *float64
MinSpeechDurationMS *int
MinSilenceDurationMS *int
EnableLogging *bool
}
RealtimeTranscriptRequest configures a realtime speech-to-text session.
type RealtimeTranscriptSession ¶
type RealtimeTranscriptSession struct {
// contains filtered or unexported fields
}
RealtimeTranscriptSession is an active realtime speech-to-text WebSocket session.
func (*RealtimeTranscriptSession) Close ¶
func (s *RealtimeTranscriptSession) Close() error
Close closes the realtime transcription session.
func (*RealtimeTranscriptSession) Receive ¶
func (s *RealtimeTranscriptSession) Receive() (*RealtimeTranscriptEvent, error)
Receive reads one event from the realtime transcription session.
func (*RealtimeTranscriptSession) SendAudioChunk ¶
func (s *RealtimeTranscriptSession) SendAudioChunk(chunk RealtimeAudioChunk) error
SendAudioChunk sends one audio chunk to the realtime transcription session.
type RealtimeTranscriptWord ¶
type RealtimeTranscriptWord struct {
Text string `json:"text"`
Start float64 `json:"start,omitempty"`
End float64 `json:"end,omitempty"`
Type string `json:"type,omitempty"`
SpeakerID string `json:"speaker_id,omitempty"`
Logprob float64 `json:"logprob,omitempty"`
Characters []string `json:"characters,omitempty"`
}
RealtimeTranscriptWord is word-level data in a realtime transcript event.
type Response ¶
type Response[T any] struct { Data T RawResponse RawResponse }
Response contains parsed API data and HTTP response metadata.
type RetryConfig ¶
type RetryConfig struct {
MaxAttempts int
BaseDelay time.Duration
MaxDelay time.Duration
StatusCodes []int
}
RetryConfig configures automatic retries for replayable requests.
MaxAttempts is the total number of attempts, including the initial request. Values less than or equal to 1 disable retries.
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
DefaultRetryConfig returns the default retry policy.
type Transcript ¶
type Transcript struct {
Text string `json:"text,omitempty"`
LanguageCode string `json:"language_code,omitempty"`
LanguageProbability float64 `json:"language_probability,omitempty"`
Words []TranscriptWord `json:"words,omitempty"`
ChannelIndex *int `json:"channel_index,omitempty"`
AdditionalFormats []TranscriptAdditionalFormat `json:"additional_formats,omitempty"`
TranscriptionID string `json:"transcription_id,omitempty"`
AudioDurationSecs *float64 `json:"audio_duration_secs,omitempty"`
Entities []DetectedEntity `json:"entities,omitempty"`
Transcripts []Transcript `json:"transcripts,omitempty"`
}
Transcript is a speech-to-text transcript response.
func (Transcript) Chunks ¶
func (t Transcript) Chunks() []Transcript
Chunks returns the channel-level transcripts when present, otherwise the transcript itself as a single chunk.
type TranscriptAdditionalFormat ¶
type TranscriptAdditionalFormat struct {
RequestedFormat string `json:"requested_format"`
FileExtension string `json:"file_extension"`
ContentType string `json:"content_type"`
IsBase64Encoded bool `json:"is_base64_encoded"`
Content string `json:"content"`
}
TranscriptAdditionalFormat is an additional transcript export returned by the API.
type TranscriptAdditionalFormatOptions ¶
type TranscriptAdditionalFormatOptions struct {
Format string `json:"format"`
IncludeSpeakers *bool `json:"include_speakers,omitempty"`
IncludeTimestamps *bool `json:"include_timestamps,omitempty"`
SegmentOnSilenceLongerThanS *float64 `json:"segment_on_silence_longer_than_s,omitempty"`
MaxSegmentDurationS *float64 `json:"max_segment_duration_s,omitempty"`
MaxSegmentChars *int `json:"max_segment_chars,omitempty"`
MaxCharactersPerLine *int `json:"max_characters_per_line,omitempty"`
}
TranscriptAdditionalFormatOptions configures an additional transcript export format.
type TranscriptCharacter ¶
type TranscriptCharacter struct {
Text string `json:"text"`
Start *float64 `json:"start,omitempty"`
End *float64 `json:"end,omitempty"`
}
TranscriptCharacter is a character-level transcript segment.
type TranscriptWebhookResponse ¶
type TranscriptWebhookResponse struct {
Message string `json:"message"`
RequestID string `json:"request_id"`
TranscriptionID *string `json:"transcription_id,omitempty"`
}
TranscriptWebhookResponse is returned when a transcript is submitted for asynchronous webhook processing.
type TranscriptWord ¶
type TranscriptWord struct {
Text string `json:"text"`
Type string `json:"type,omitempty"`
Start *float64 `json:"start,omitempty"`
End *float64 `json:"end,omitempty"`
SpeakerID string `json:"speaker_id,omitempty"`
Logprob float64 `json:"logprob,omitempty"`
Characters []TranscriptCharacter `json:"characters,omitempty"`
ChannelIndex *int `json:"channel_index,omitempty"`
}
TranscriptWord is a word-level transcript segment.
type UploadProgress ¶
type UploadProgress struct {
SentBytes int64
// TotalBytes is -1 when the upload size cannot be determined.
TotalBytes int64
Done bool
// Attempt starts at 1 and increments when a replayable upload is retried.
Attempt int
}
UploadProgress reports uploaded file bytes for a transcript request.
type User ¶
type User struct {
UserID string `json:"user_id,omitempty"`
Subscription *UserSubscription `json:"subscription,omitempty"`
IsNewUser bool `json:"is_new_user,omitempty"`
XIAPIKey string `json:"xi_api_key,omitempty"`
CanUseDelayedPaymentMethods bool `json:"can_use_delayed_payment_methods,omitempty"`
IsOnboardingCompleted bool `json:"is_onboarding_completed,omitempty"`
FirstName string `json:"first_name,omitempty"`
CreatedAt int64 `json:"created_at,omitempty"`
SeatType string `json:"seat_type,omitempty"`
IsAPIKeyHashed bool `json:"is_api_key_hashed,omitempty"`
XIAPIKeyPreview string `json:"xi_api_key_preview,omitempty"`
ShowComplianceTerms bool `json:"show_compliance_terms,omitempty"`
AvailableModels []string `json:"available_models,omitempty"`
NextInvoice *UserInvoice `json:"next_invoice,omitempty"`
}
User contains account metadata returned by the ElevenLabs user endpoint.
type UserInvoice ¶
type UserInvoice struct {
AmountDueCents int64 `json:"amount_due_cents,omitempty"`
NextPaymentAttemptUnix int64 `json:"next_payment_attempt_unix,omitempty"`
}
UserInvoice contains upcoming invoice metadata.
type UserSubscription ¶
type UserSubscription struct {
Tier string `json:"tier,omitempty"`
CharacterCount int64 `json:"character_count,omitempty"`
CharacterLimit int64 `json:"character_limit,omitempty"`
CanExtendCharacterLimit bool `json:"can_extend_character_limit,omitempty"`
AllowedToExtendCharacterLimit bool `json:"allowed_to_extend_character_limit,omitempty"`
NextCharacterCountResetUnix int64 `json:"next_character_count_reset_unix,omitempty"`
VoiceLimit int64 `json:"voice_limit,omitempty"`
MaxVoiceAddEdits int64 `json:"max_voice_add_edits,omitempty"`
VoiceAddEditCounter int64 `json:"voice_add_edit_counter,omitempty"`
ProfessionalVoiceLimit int64 `json:"professional_voice_limit,omitempty"`
CanExtendVoiceLimit bool `json:"can_extend_voice_limit,omitempty"`
CanUseInstantVoiceCloning bool `json:"can_use_instant_voice_cloning,omitempty"`
CanUseProfessionalVoiceCloning bool `json:"can_use_professional_voice_cloning,omitempty"`
Currency string `json:"currency,omitempty"`
Status string `json:"status,omitempty"`
BillingPeriod string `json:"billing_period,omitempty"`
CharacterRefreshPeriod string `json:"character_refresh_period,omitempty"`
NextInvoice *UserInvoice `json:"next_invoice,omitempty"`
HasOpenInvoices bool `json:"has_open_invoices,omitempty"`
CanUsePVCInstantly bool `json:"can_use_pvc_instantly,omitempty"`
CanUseVoiceDesign bool `json:"can_use_voice_design,omitempty"`
CanUseInstantVoiceCloningTrial bool `json:"can_use_instant_voice_cloning_trial,omitempty"`
CanUseProfessionalVoiceCloningTrial bool `json:"can_use_professional_voice_cloning_trial,omitempty"`
}
UserSubscription contains subscription and quota metadata for a user.
type ValidationError ¶
type ValidationError struct {
Loc []any `json:"loc"`
Msg string `json:"msg"`
Type string `json:"type"`
}
ValidationError contains validation details returned by the ElevenLabs API.