deepgram

package
v0.68.13 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

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

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 {
	Configured            bool
	SmartFormat           bool
	Dictation             bool
	FillerWords           bool
	Numerals              bool
	DetectLanguage        bool
	LanguageOverride      string
	UseVocabularyKeyterms bool
	Keyterms              []string
	EndpointingMs         int
}

Options holds provider-specific Deepgram STT controls. These map to Deepgram Listen query parameters while keeping SpeechKit's public STT router interface provider-neutral.

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
	Keyterms              []string
	EndpointingMs         int
	// contains filtered or unexported fields
}

Provider transcribes through the Deepgram Listen API.

func New

func New(apiKey, model string) *Provider

New creates a Deepgram provider. Model defaults to the provider default if empty.

func (*Provider) ApplyOptions added in v0.64.3

func (p *Provider) ApplyOptions(opts Options)

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

func (*Provider) Name added in v0.64.3

func (p *Provider) Name() string

func (*Provider) StartDictationStream added in v0.64.3

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)

func (*Provider) Transcribe added in v0.64.3

func (p *Provider) Transcribe(ctx context.Context, audio []byte, opts stt.TranscribeOpts) (*stt.Result, error)

Jump to

Keyboard shortcuts

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