Documentation
¶
Overview ¶
Package pcmtts adapts the speech providers that answer one HTTP POST with a PCM stream: Deepgram, ElevenLabs, and Cartesia.
Their request shapes differ - the voice is in the path for one, in the body for another, and the sample rate is a query parameter, a format string, and a nested object respectively - but the response is the same thing in all three cases, and it is the response that is hard. So the request is a small per-vendor profile and the streaming, resampling, and terminal-chunk logic is shared with every other speech adapter here.
A provider whose speech endpoint speaks OpenAI's /v1/audio/speech contract belongs in adapters/openaitts instead. This package is for the ones that do not.
Index ¶
Constants ¶
const ( // DeepgramEndpoint is Deepgram's speech route. DeepgramEndpoint = "https://api.deepgram.com/v1/speak" // DeepgramDefaultModel is a Deepgram Aura voice. Deepgram names the voice // and the model together, so there is no separate voice field. DeepgramDefaultModel = "aura-2-thalia-en" // ElevenLabsEndpoint is the streaming route, with the voice in the path. ElevenLabsEndpoint = "https://api.elevenlabs.io/v1/text-to-speech" // ElevenLabsDefaultModel is the low-latency multilingual model. ElevenLabsDefaultModel = "eleven_flash_v2_5" // CartesiaEndpoint is Cartesia's raw-bytes route. CartesiaEndpoint = "https://api.cartesia.ai/tts/bytes" // CartesiaDefaultModel is Cartesia's low-latency model. CartesiaDefaultModel = "sonic-2" // CartesiaDefaultVersion is the dated API version Cartesia requires in a // header. It is a date rather than a number and is worth checking against // their documentation before a deployment. CartesiaDefaultVersion = "2024-11-13" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
Adapter is safe for concurrent use. Each Stream call owns its request.
func NewCartesia ¶
NewCartesia creates a Cartesia speech client.
func NewDeepgram ¶
NewDeepgram creates a Deepgram speech client.
func NewElevenLabs ¶
NewElevenLabs creates an ElevenLabs speech client. The voice is part of the path, so it is required rather than optional.
func (*Adapter) Descriptor ¶
func (adapter *Adapter) Descriptor() v1.Descriptor
Descriptor implements api/v1.SpeechProvider.
func (*Adapter) Stream ¶
func (adapter *Adapter) Stream( ctx context.Context, plan v1.SpeechPlan, consume func(v1.SpeechChunk) error, ) error
Stream implements api/v1.StreamingSpeechProvider.
func (*Adapter) Synthesize ¶
func (adapter *Adapter) Synthesize(ctx context.Context, plan v1.SpeechPlan) ([]v1.SpeechChunk, error)
Synthesize collects Stream output for consumers that require the stable non-streaming interface.
type Config ¶
type Config struct {
APIKey string
// Model is the vendor's model or voice-model identifier.
Model string
// Voice selects the speaker where the vendor separates it from the model.
// Deepgram does not, and rejects a voice.
Voice string
// Endpoint overrides the vendor's URL, for a proxy or a region.
Endpoint string
// Language is a BCP-47 hint where the vendor accepts one.
Language string
// RequestSampleRateHz is the rate asked of the provider. Asking for the
// output rate directly avoids a resample; a vendor that cannot produce it
// returns something else and the shared reader resamples.
RequestSampleRateHz uint32
// OutputSampleRateHz is the rate chunks are emitted at.
OutputSampleRateHz uint32
// APIVersion is the dated version header Cartesia requires.
APIVersion string
// ExtraBody adds vendor-specific top-level body fields.
ExtraBody map[string]json.RawMessage
// Headers adds request headers.
Headers http.Header
HTTPClient *http.Client
RequestTimeout time.Duration
ReadBufferBytes int
MaxAudioBytes int64
}
Config configures one speech client. The same fields mean the same thing for every vendor; what differs is where they end up in the request.