Documentation
¶
Overview ¶
Package deepgram adapts Deepgram's streaming recogniser and its speech endpoint to the stable OpenRealtime component API.
Deepgram is here rather than behind the generic transcription adapter for one reason: it actually streams. A batch endpoint can only be asked what a recording said, so a partial hypothesis costs a full re-transcription; Deepgram emits interim results as the audio arrives, which is what the stable-partial observation policy was written for.
Index ¶
- Constants
- type LanguageMux
- func (mux *LanguageMux) Close() error
- func (mux *LanguageMux) Descriptor() v1.Descriptor
- func (mux *LanguageMux) Finalize(ctx context.Context, sourceSample uint64) (v1.PerceptionRevision, error)
- func (mux *LanguageMux) PushFrame(ctx context.Context, frame v1.AudioFrame) ([]v1.PerceptionRevision, error)
- func (mux *LanguageMux) SpeechEndpointed() bool
- type ListenConfig
- type Listener
- func (listener *Listener) Close() error
- func (listener *Listener) Confidence() float64
- func (listener *Listener) Descriptor() v1.Descriptor
- func (listener *Listener) Finalize(ctx context.Context, sourceSample uint64) (v1.PerceptionRevision, error)
- func (listener *Listener) PushFrame(ctx context.Context, frame v1.AudioFrame) ([]v1.PerceptionRevision, error)
- func (listener *Listener) SpeechEndpointed() bool
Constants ¶
const ( // DefaultListenURL is Deepgram's streaming recognition endpoint. DefaultListenURL = "wss://api.deepgram.com/v1/listen" // DefaultListenModel is the general-purpose streaming model. Deepgram // also ships a turn-taking model for voice agents; this adapter does its // own turn-taking, so the general model is the right default here. DefaultListenModel = "nova-3" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LanguageMux ¶
type LanguageMux struct {
// contains filtered or unexported fields
}
LanguageMux keeps two explicitly selected Deepgram language streams over the same utterance. Deepgram's streaming language detection is unavailable, and Nova-3's native multi mode does not include Mandarin. A deployment that knows it needs English and Mandarin therefore has to preserve both readings until the script itself distinguishes them.
The first language is the ordinary/default lane. The second must be a Chinese locale. A lane wins only after Deepgram gives its current reading a high confidence; this keeps both an English phonetic rendering of Mandarin and a Chinese model's occasional Han-like rendering of English away from the transcript-event policy. Once selected, the lane remains fixed for the utterance.
func NewLanguageMux ¶
func NewLanguageMux(config ListenConfig, languages []string) (*LanguageMux, error)
NewLanguageMux creates an explicit English/Chinese streaming recogniser. Both lanes use the same Deepgram model and connection settings; only the service language restriction differs.
func (*LanguageMux) Close ¶
func (mux *LanguageMux) Close() error
func (*LanguageMux) Descriptor ¶
func (mux *LanguageMux) Descriptor() v1.Descriptor
func (*LanguageMux) Finalize ¶
func (mux *LanguageMux) Finalize( ctx context.Context, sourceSample uint64, ) (v1.PerceptionRevision, error)
func (*LanguageMux) PushFrame ¶
func (mux *LanguageMux) PushFrame( ctx context.Context, frame v1.AudioFrame, ) ([]v1.PerceptionRevision, error)
func (*LanguageMux) SpeechEndpointed ¶
func (mux *LanguageMux) SpeechEndpointed() bool
type ListenConfig ¶
type ListenConfig struct {
// URL is the WebSocket endpoint. Empty selects DefaultListenURL.
URL string
// Model is the recognition model.
Model string
// APIKey is the Deepgram key. It is sent as an Authorization: Token
// header rather than in the URL, so it does not reach proxy logs.
APIKey string
// Language selects recognition language. Empty leaves Deepgram's service
// default in force. The model-specific "multi" value is not automatic
// detection for every language; for example, Nova-3 multi does not include
// Mandarin, which requires a Chinese locale such as zh-CN.
Language string
// InterimResults asks for hypotheses before a segment is finished. It
// defaults on, because the reason to choose a streaming recogniser is to
// get text before the speaker stops.
InterimResults *bool
// SmartFormat applies Deepgram's punctuation and entity formatting.
SmartFormat *bool
// Endpointing is the silence Deepgram's own VAD requires before marking a
// Results event speech_final. Zero leaves the service default in force.
Endpointing time.Duration
// VADEvents asks Deepgram to expose its speech detector. It defaults on;
// the adapter currently consumes speech_final and retains the explicit
// switch so deployments can make the wire behavior reproducible.
VADEvents *bool
// Keywords biases recognition toward expected vocabulary.
Keywords []string
// Keyterms biases Nova-3 toward exact words or phrases. Deepgram accepts
// this option as a repeated singular keyterm query parameter; keeping it
// distinct from the legacy weighted keywords option prevents a frozen
// deployment from silently changing wire semantics.
Keyterms []string
// Extra adds query parameters this adapter does not model.
Extra map[string]string
// Header adds request headers.
Header http.Header
// DialTimeout bounds connection setup.
DialTimeout time.Duration
// DrainTimeout bounds how long Finalize waits for Deepgram to flush the
// results it still owes after the stream is closed.
DrainTimeout time.Duration
// WriteTimeout bounds one send on an established stream. Zero selects the
// shipped default; a negative value removes the bound.
//
// The dial and the drain were bounded and the sends between them were not,
// which leaves the one call on the hot path unbounded: PushFrame writes a
// frame every cadence, holding this listener's lock, on a context that
// comes from the session and therefore has no deadline. A stalled socket
// there does not slow recognition down, it stops it - and the block
// propagates back through the observer to the binding and then to the
// session's own event loop.
//
// The bound is this provider's cadence rather than a shared default: a
// frame of audio is a few kilobytes, and a streaming recogniser that has
// not accepted one in five seconds is not keeping up with a conversation
// whatever it does next.
WriteTimeout time.Duration
// HTTPClient dials the WebSocket. Empty uses the default client, which is
// what a test server needs overridden.
HTTPClient *http.Client
}
ListenConfig configures one recognition utterance.
The audio sample rate is deliberately absent: it is taken from the first frame and declared to Deepgram, so nothing is resampled on the way in. A recogniser that resamples before recognising has thrown away information no later stage can recover.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener is one recognition utterance. It is safe for concurrent use, and like every perception provider here it represents exactly one stream.
func NewListener ¶
func NewListener(config ListenConfig) (*Listener, error)
NewListener validates configuration and returns a fresh utterance.
func (*Listener) Close ¶
Close releases the connection for a session that ends without an endpoint.
It exists because an utterance can be abandoned rather than finished - the speaker stops, the session ends, the caller hangs up - and a streaming recogniser holds a socket and a goroutine that nothing else will reclaim. The audio observer closes the provider it drops for exactly this reason.
func (*Listener) Confidence ¶
Confidence is Deepgram's confidence in the transcript currently exposed by this stream. It is retained across an empty endpoint marker because that marker closes the preceding text; it does not replace it with a hypothesis that the speaker said nothing.
func (*Listener) Descriptor ¶
func (listener *Listener) Descriptor() v1.Descriptor
Descriptor implements api/v1.PerceptionProvider.
func (*Listener) Finalize ¶
func (listener *Listener) Finalize( ctx context.Context, sourceSample uint64, ) (v1.PerceptionRevision, error)
Finalize closes the stream, waits for the results Deepgram still owes, and emits one final revision.
func (*Listener) PushFrame ¶
func (listener *Listener) PushFrame( ctx context.Context, frame v1.AudioFrame, ) ([]v1.PerceptionRevision, error)
PushFrame sends one contiguous PCM16LE frame and returns whatever Deepgram has said since the previous call.
func (*Listener) SpeechEndpointed ¶
SpeechEndpointed reports that Deepgram's own VAD marked the current utterance complete. It is an optional capability consumed by the event-aware cascade path; the existing acoustic endpoint path never asks.