Documentation
¶
Overview ¶
Package deepgram adapts Deepgram's speech APIs to stt.STTProvider: the Listen REST endpoint (/v1/listen) for batch transcription, the Listen WebSocket for live dictation and speaker streams, and Flux (/v2/listen) for conversational turn detection. It needs a Deepgram API key and public https egress; there is no local component.
Stability: Beta — API-checked; may change with a changelog callout.
Index ¶
- Constants
- func ParseKeyterms(raw string) []string
- type FluxStreamOptions
- type FluxTurn
- type FluxTurnStream
- type FluxWord
- type Options
- type Provider
- func (p *Provider) ApplyTuning(opts Tuning)
- func (*Provider) Capabilities() []speechkit.Capability
- func (p *Provider) Health(ctx context.Context) error
- func (p *Provider) Name() string
- func (p *Provider) StartDictationStream(ctx context.Context, opts speechkit.DictationStreamOptions, ...) (speechkit.DictationStream, error)
- func (p *Provider) StartFluxTurnStream(ctx context.Context, opts FluxStreamOptions, format speaker.AudioFormat) (*FluxTurnStream, error)
- func (p *Provider) StartSpeakerStream(ctx context.Context, opts speaker.Options, format speaker.AudioFormat) (speaker.SpeakerStream, error)
- func (p *Provider) Transcribe(ctx context.Context, audio []byte, opts stt.TranscribeOpts) (*stt.Result, error)
- type Tuning
Constants ¶
const ( FluxEventStartOfTurn = "StartOfTurn" FluxEventUpdate = "Update" FluxEventEagerEndOfTurn = "EagerEndOfTurn" FluxEventTurnResumed = "TurnResumed" FluxEventEndOfTurn = "EndOfTurn" )
Flux turn lifecycle events. A turn opens with StartOfTurn, grows through Update events, and closes with EndOfTurn. EagerEndOfTurn is a speculative signal — the model believes the speaker is done and a consumer may start generating a response — which TurnResumed retracts when the speaker continues.
const ( FluxEOTThresholdMin = 0.5 FluxEOTThresholdMax = 0.9 FluxEagerEOTThresholdMin = 0.3 FluxEagerEOTThresholdMax = 0.9 FluxEOTTimeoutMinMs = 500 FluxEOTTimeoutMaxMs = 60000 )
Flux tuning ranges, per the Deepgram Flux API reference.
const ( DeepgramFluxModelEN = "flux-general-en" DeepgramFluxModelMulti = "flux-general-multi" )
Deepgram Flux model identifiers.
const FluxAudioChunk = 80 * time.Millisecond
FluxAudioChunk is the chunk duration Deepgram recommends for Flux input.
Variables ¶
This section is empty.
Functions ¶
func ParseKeyterms ¶ added in v0.64.3
ParseKeyterms splits a free-text vocabulary list on newlines, commas and semicolons into Deepgram keyterms: trimmed, de-duplicated case-insensitively and capped at 100. It returns nil for blank input.
Types ¶
type FluxStreamOptions ¶
type FluxStreamOptions struct {
// Model selects flux-general-en or flux-general-multi. Empty uses the
// multilingual model, which is the point of Flux for SpeechKit: it detects
// and switches languages within a single conversation.
Model string
// LanguageHints biases recognition toward the given BCP-47 languages. Only
// flux-general-multi accepts hints; they narrow the model, they do not pin
// it, and every turn still reports what it actually heard.
LanguageHints []string
// Keyterms boost domain vocabulary (product names and other terms the model
// has not seen).
Keyterms []string
// EOTThreshold, EagerEOTThreshold, and EOTTimeoutMs tune turn detection.
// Zero keeps Deepgram's defaults; out-of-range values are clamped.
EOTThreshold float64
EagerEOTThreshold float64
EOTTimeoutMs int
}
FluxStreamOptions configures a Flux turn stream. The zero value is valid and selects the multilingual model with Deepgram's default turn detection.
type FluxTurn ¶
type FluxTurn struct {
// Event is one of the Flux lifecycle events above.
Event string `json:"event"`
// TurnIndex counts turns within the connection.
TurnIndex int `json:"turnIndex"`
// Transcript is the full turn transcript so far, not a delta.
Transcript string `json:"transcript"`
Words []FluxWord `json:"words,omitempty"`
// Languages are the languages actually detected in this turn; empty when
// the turn holds no speech yet.
Languages []string `json:"languages,omitempty"`
// EndOfTurnConfidence is the model's confidence that the speaker is done.
EndOfTurnConfidence float64 `json:"endOfTurnConfidence"`
// AudioWindowStartMs/EndMs bound the audio this turn covers.
AudioWindowStartMs int64 `json:"audioWindowStartMs"`
AudioWindowEndMs int64 `json:"audioWindowEndMs"`
// SequenceID is Deepgram's per-connection event counter.
SequenceID int64 `json:"sequenceId"`
// RequestID identifies the connection in Deepgram's logs.
RequestID string `json:"requestId"`
// LatencyMs is the time from stream open to this event.
LatencyMs int64 `json:"latencyMs"`
}
FluxTurn is one decoded TurnInfo event.
func (FluxTurn) IsFinal ¶ added in v0.64.3
IsFinal reports whether the turn is closed and the transcript will not grow.
func (FluxTurn) IsSpeculative ¶ added in v0.64.3
IsSpeculative reports whether the event is the eager end-of-turn signal, which TurnResumed can retract. A consumer may start work on it, but must be able to cancel that work.
type FluxTurnStream ¶
type FluxTurnStream struct {
// contains filtered or unexported fields
}
FluxTurnStream is a live Flux connection. Callers push PCM with SendPCM and read turn events with Receive until io.EOF.
func (*FluxTurnStream) Close ¶ added in v0.64.3
func (s *FluxTurnStream) Close() error
Close shuts the WebSocket down. It is safe to call more than once.
func (*FluxTurnStream) CloseStream ¶ added in v0.64.3
func (s *FluxTurnStream) CloseStream(ctx context.Context) error
CloseStream tells Deepgram no further audio is coming, so it can flush the open turn instead of waiting for the end-of-turn timeout.
func (*FluxTurnStream) Model ¶ added in v0.64.3
func (s *FluxTurnStream) Model() string
Model reports the Flux model this stream negotiated.
type FluxWord ¶
type FluxWord struct {
Text string `json:"text"`
Confidence float64 `json:"confidence"`
StartMs int64 `json:"startMs"`
EndMs int64 `json:"endMs"`
}
FluxWord is a single recognized word. Flux reports no speaker label and no separately punctuated form — the turn transcript carries the punctuation.
type Options ¶
type Options struct {
// APIKey is the Deepgram API key.
APIKey string
// Model is the Deepgram model. Empty selects "nova-3".
Model string
}
Options configures New.
type Provider ¶
type Provider struct {
APIKey string
Model string
DiarizationModel string
BaseURL string
Validation netsec.ValidationOptions
SmartFormat bool
Dictation bool
FillerWords bool
Numerals bool
DetectLanguage bool
LanguageOverride string
UseVocabularyKeyterms bool
// NoStore opts every request out of Deepgram's Model Improvement
// Partnership Program, so audio and transcript are kept only for as long
// as answering takes. Set by the host from its retention policy; the batch
// path also honours the per-request option.
NoStore bool
Keyterms []string
EndpointingMs int
// Logger receives this provider's diagnostics. Nil falls back to
// slog.Default() at log time.
Logger *slog.Logger
// contains filtered or unexported fields
}
Provider transcribes through the Deepgram Listen API.
func (*Provider) ApplyTuning ¶ added in v0.74.0
ApplyTuning copies opts onto the provider, replacing the flags New set (SmartFormat and Numerals default on) rather than merging with them. Keyterms are trimmed, de-duplicated case-insensitively and capped at 100; a negative EndpointingMs keeps the current value.
func (*Provider) Capabilities ¶ added in v0.64.3
func (*Provider) Capabilities() []speechkit.Capability
Capabilities reports what this provider does beyond plain transcription.
func (*Provider) Health ¶ added in v0.64.3
Health issues an authenticated GET /v1/projects; a transport failure or non-200 status is returned as the error.
func (*Provider) StartDictationStream ¶ added in v0.64.3
func (p *Provider) StartDictationStream(ctx context.Context, opts speechkit.DictationStreamOptions, format speaker.AudioFormat) (speechkit.DictationStream, error)
StartDictationStream implements speechkit.DictationStreamProvider. With opts.CompleteCapture the capture is uploaded to the Listen REST endpoint while it is recorded and the stream's only final is the transcript of the whole recording (see completeCaptureStream); otherwise the stream is the Listen WebSocket, which finalizes utterance by utterance.
func (*Provider) StartFluxTurnStream ¶ added in v0.64.3
func (p *Provider) StartFluxTurnStream(ctx context.Context, opts FluxStreamOptions, format speaker.AudioFormat) (*FluxTurnStream, error)
StartFluxTurnStream opens a Deepgram Flux /v2/listen stream. The format must be raw PCM; Deepgram recommends 16 kHz mono and FluxAudioChunk-sized writes.
func (*Provider) StartSpeakerStream ¶ added in v0.64.3
func (p *Provider) StartSpeakerStream(ctx context.Context, opts speaker.Options, format speaker.AudioFormat) (speaker.SpeakerStream, error)
StartSpeakerStream implements speaker.StreamingProvider over the Listen WebSocket with diarization and utterances on. opts must ask for diarization; the model is opts.Model, else the configured Model, else "nova-3", and the provider's formatting flags, keyterms and endpointing apply.
func (*Provider) Transcribe ¶ added in v0.64.3
func (p *Provider) Transcribe(ctx context.Context, audio []byte, opts stt.TranscribeOpts) (*stt.Result, error)
Transcribe implements stt.STTProvider over POST /v1/listen. The model is the request override, else the configured Model, else "nova-3"; the language is the resolved locale, else Deepgram's multilingual "multi"; keyterms, formatting flags, the MIP opt-out and diarization travel as query parameters. The result carries the best alternative's text, confidence and per-word confidences, the detected language when reported, and speaker segments when diarization was requested.
type Tuning ¶ added in v0.74.0
type Tuning struct {
Configured bool
SmartFormat bool
Dictation bool
FillerWords bool
Numerals bool
DetectLanguage bool
LanguageOverride string
UseVocabularyKeyterms bool
Keyterms []string
EndpointingMs int
}
Tuning holds provider-specific Deepgram STT controls. These map to Deepgram Listen query parameters while keeping SpeechKit's public STT router interface provider-neutral. Apply them with Provider.ApplyTuning.