pcmtts

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func NewCartesia(config Config) (*Adapter, error)

NewCartesia creates a Cartesia speech client.

func NewDeepgram

func NewDeepgram(config Config) (*Adapter, error)

NewDeepgram creates a Deepgram speech client.

func NewElevenLabs

func NewElevenLabs(config Config) (*Adapter, error)

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.

Jump to

Keyboard shortcuts

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