audioproviders

package
v1.8.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package audioproviders implements audio.tts.Generation and audio.stt.SpeechToText for supported providers. Add a new file per provider (elevenlabs_tts.go, deepgram_stt.go, …) — no other package needs updating.

Index

Constants

View Source
const APIElevenLabs = "elevenlabs"

APIElevenLabs marks a profile served by the ElevenLabs clients.

View Source
const ResponseFormatOmit = "omit"

ResponseFormatOmit tells a client not to send a response_format field.

Variables

This section is empty.

Functions

This section is empty.

Types

type Capability added in v1.8.0

type Capability struct {
	Models []string
}

Capability lists the models of one direction. The first model is the default.

func (*Capability) DefaultModel added in v1.8.0

func (c *Capability) DefaultModel() string

DefaultModel returns the model used when the host does not name one.

type ElevenLabsSTT added in v1.8.0

type ElevenLabsSTT struct {
	// contains filtered or unexported fields
}

ElevenLabsSTT transcribes audio with ElevenLabs Scribe.

func NewElevenLabsSTT added in v1.8.0

func NewElevenLabsSTT(apiKey string, opts ...ElevenLabsSTTOption) *ElevenLabsSTT

NewElevenLabsSTT creates an ElevenLabs Scribe client.

func (*ElevenLabsSTT) Provider added in v1.8.0

func (c *ElevenLabsSTT) Provider() string

func (*ElevenLabsSTT) Transcribe added in v1.8.0

func (c *ElevenLabsSTT) Transcribe(ctx context.Context, audioData []byte) (*stt.Response, error)

type ElevenLabsSTTOption added in v1.8.0

type ElevenLabsSTTOption func(*ElevenLabsSTT)

ElevenLabsSTTOption configures an ElevenLabsSTT client.

func WithElevenLabsSTTBaseURL added in v1.8.0

func WithElevenLabsSTTBaseURL(baseURL string) ElevenLabsSTTOption

func WithElevenLabsSTTHTTPClient added in v1.8.0

func WithElevenLabsSTTHTTPClient(hc *http.Client) ElevenLabsSTTOption

func WithElevenLabsSTTLanguage added in v1.8.0

func WithElevenLabsSTTLanguage(language string) ElevenLabsSTTOption

func WithElevenLabsSTTModel added in v1.8.0

func WithElevenLabsSTTModel(model string) ElevenLabsSTTOption

type ElevenLabsTTS added in v1.8.0

type ElevenLabsTTS struct {
	// contains filtered or unexported fields
}

ElevenLabsTTS synthesises speech with ElevenLabs.

func NewElevenLabsTTS added in v1.8.0

func NewElevenLabsTTS(apiKey string, opts ...ElevenLabsTTSOption) *ElevenLabsTTS

NewElevenLabsTTS creates an ElevenLabs text-to-speech client.

func (*ElevenLabsTTS) GenerateAudio added in v1.8.0

func (c *ElevenLabsTTS) GenerateAudio(ctx context.Context, text string) (*tts.Response, error)

func (*ElevenLabsTTS) ListVoices added in v1.8.0

func (c *ElevenLabsTTS) ListVoices(ctx context.Context) ([]tts.Voice, error)

ListVoices returns the voices of the account (first page, up to 100).

func (*ElevenLabsTTS) Provider added in v1.8.0

func (c *ElevenLabsTTS) Provider() string

type ElevenLabsTTSOption added in v1.8.0

type ElevenLabsTTSOption func(*ElevenLabsTTS)

ElevenLabsTTSOption configures an ElevenLabsTTS client.

func WithElevenLabsTTSBaseURL added in v1.8.0

func WithElevenLabsTTSBaseURL(baseURL string) ElevenLabsTTSOption

func WithElevenLabsTTSFormat added in v1.8.0

func WithElevenLabsTTSFormat(format string) ElevenLabsTTSOption

WithElevenLabsTTSFormat sets the output format: mp3, wav, opus or pcm, or a full ElevenLabs output_format such as mp3_44100_192.

func WithElevenLabsTTSHTTPClient added in v1.8.0

func WithElevenLabsTTSHTTPClient(hc *http.Client) ElevenLabsTTSOption

func WithElevenLabsTTSModel added in v1.8.0

func WithElevenLabsTTSModel(model string) ElevenLabsTTSOption

func WithElevenLabsTTSVoice added in v1.8.0

func WithElevenLabsTTSVoice(voice string) ElevenLabsTTSOption

WithElevenLabsTTSVoice sets the voice_id (see ListVoices).

type OpenAISTT

type OpenAISTT struct {
	// contains filtered or unexported fields
}

OpenAISTT transcribes audio through an OpenAI-compatible /audio/transcriptions endpoint: OpenAI itself, Groq, Mistral, or any self-hosted server that speaks the same API (see the profiles in catalog.go).

func NewOpenAISTT

func NewOpenAISTT(apiKey string, opts ...OpenAISTTOption) *OpenAISTT

NewOpenAISTT creates an OpenAI Whisper STT client. audioData passed to Transcribe may be MP3, MP4, MPEG, MPGA, M4A, WAV, or WebM.

func (*OpenAISTT) Provider

func (c *OpenAISTT) Provider() string

func (*OpenAISTT) Transcribe

func (c *OpenAISTT) Transcribe(ctx context.Context, audioData []byte) (*stt.Response, error)

type OpenAISTTOption

type OpenAISTTOption func(*OpenAISTT)

OpenAISTTOption configures an OpenAISTT client.

func WithSTTBaseURL

func WithSTTBaseURL(url string) OpenAISTTOption

func WithSTTHTTPClient

func WithSTTHTTPClient(hc *http.Client) OpenAISTTOption

func WithSTTLanguage

func WithSTTLanguage(lang string) OpenAISTTOption

func WithSTTModel

func WithSTTModel(model string) OpenAISTTOption

func WithSTTProviderName added in v1.8.0

func WithSTTProviderName(name string) OpenAISTTOption

WithSTTProviderName sets the name Provider() reports (default "openai").

func WithSTTResponseFormat added in v1.8.0

func WithSTTResponseFormat(format string) OpenAISTTOption

WithSTTResponseFormat forces the response_format sent with the request. Empty means "choose from the model" (verbose_json for Whisper models, which carry segments and timings; json for the others, which reject verbose_json); ResponseFormatOmit sends no response_format at all, for servers that do not take one.

type OpenAITTS

type OpenAITTS struct {
	// contains filtered or unexported fields
}

OpenAITTS generates speech using the OpenAI TTS API.

func NewOpenAITTS

func NewOpenAITTS(apiKey string, opts ...OpenAITTSOption) *OpenAITTS

NewOpenAITTS creates an OpenAI TTS client. Models: gpt-4o-mini-tts (default), tts-1, tts-1-hd; any OpenAI-compatible /audio/speech server works through WithTTSBaseURL.

func (*OpenAITTS) GenerateAudio

func (c *OpenAITTS) GenerateAudio(ctx context.Context, text string) (*tts.Response, error)

func (*OpenAITTS) ListVoices

func (c *OpenAITTS) ListVoices(_ context.Context) ([]tts.Voice, error)

func (*OpenAITTS) Provider

func (c *OpenAITTS) Provider() string

type OpenAITTSOption

type OpenAITTSOption func(*OpenAITTS)

OpenAITTSOption configures an OpenAITTS client.

func WithTTSBaseURL

func WithTTSBaseURL(url string) OpenAITTSOption

func WithTTSFormat

func WithTTSFormat(fmt string) OpenAITTSOption

func WithTTSHTTPClient

func WithTTSHTTPClient(hc *http.Client) OpenAITTSOption

func WithTTSModel

func WithTTSModel(model string) OpenAITTSOption

func WithTTSProviderName added in v1.8.0

func WithTTSProviderName(name string) OpenAITTSOption

WithTTSProviderName sets the name Provider() reports (default "openai").

func WithTTSVoice

func WithTTSVoice(voice string) OpenAITTSOption

type Profile added in v1.8.0

type Profile struct {
	ID          string
	DisplayName string
	// API names the wire protocol: "" is the OpenAI-compatible audio API,
	// APIElevenLabs is ElevenLabs' own.
	API     string
	BaseURL string
	// EnvVars are the environment variables that can carry the API key,
	// read when the host passes none.
	EnvVars []string
	// STT and TTS are nil when the provider does not offer that direction.
	STT *Capability
	TTS *Capability
	// STTResponseFormat is the response_format to send for transcription:
	// "" chooses from the model, ResponseFormatOmit sends none.
	STTResponseFormat string
}

Profile describes one provider of speech: the OpenAI-compatible audio API (/audio/transcriptions, /audio/speech) or ElevenLabs, see API. It is the audio counterpart of the chat catalog in internal/providers: the SDK looks a provider up here instead of hard-coding "openai", and a provider that is not listed still works when the host gives its base URL.

func ProfileFor added in v1.8.0

func ProfileFor(id string) (Profile, bool)

ProfileFor returns the profile of a provider ID, case-insensitively.

func Profiles added in v1.8.0

func Profiles() []Profile

Profiles returns the audio providers this build knows.

func (Profile) OpenAICompatible added in v1.8.0

func (p Profile) OpenAICompatible() bool

OpenAICompatible reports whether the provider speaks the OpenAI audio API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL