deepgram

package
v0.75.6 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 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 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

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

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

View Source
const (
	DeepgramFluxModelEN    = "flux-general-en"
	DeepgramFluxModelMulti = "flux-general-multi"
)

Deepgram Flux model identifiers.

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

func ParseKeyterms(raw string) []string

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

func (t FluxTurn) IsFinal() bool

IsFinal reports whether the turn is closed and the transcript will not grow.

func (FluxTurn) IsSpeculative added in v0.64.3

func (t FluxTurn) IsSpeculative() bool

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.

func (*FluxTurnStream) Receive added in v0.64.3

func (s *FluxTurnStream) Receive(ctx context.Context) (FluxTurn, error)

Receive returns the next turn event, skipping the connection handshake and any frame that carries no turn. It returns io.EOF when Deepgram closes.

func (*FluxTurnStream) SendPCM added in v0.64.3

func (s *FluxTurnStream) SendPCM(ctx context.Context, pcm []byte) error

SendPCM streams one chunk of raw PCM.

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 New

func New(opts Options) *Provider

New creates a Deepgram provider. Zero Options values select the provider defaults.

func (*Provider) ApplyTuning added in v0.74.0

func (p *Provider) ApplyTuning(opts Tuning)

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

func (p *Provider) Health(ctx context.Context) error

Health issues an authenticated GET /v1/projects; a transport failure or non-200 status is returned as the error.

func (*Provider) Name added in v0.64.3

func (p *Provider) Name() string

Name returns "deepgram".

func (*Provider) StartDictationStream added in v0.64.3

StartDictationStream implements speechkit.DictationStreamProvider over the Listen WebSocket. The language is opts.Language, else the provider's LanguageOverride, else "multi"; endpointing is opts.EndpointingMs, else the provider's, else 700 ms; interim results are requested only when asked for. The returned stream coalesces Deepgram's is_final fragments into one final event per 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.

Jump to

Keyboard shortcuts

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