deepgram

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: BSD-2-Clause Imports: 27 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 deepgram provides Deepgram's streaming speech-to-text service (over the live transcription WebSocket, see stt.go), its Aura text-to-speech service (see tts.go), and its Flux streaming STT and TTS services (see flux.go and flux_tts.go).

The STT service pushes InterimTranscriptionFrames and TranscriptionFrames downstream. It asks Deepgram to flush the transcript as soon as the speech ends rather than wait on Deepgram's own endpointing, and the answer to that request is what marks the end of the user's turn.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFluxSTT added in v0.1.0

func NewFluxSTT(cfg FluxConfig) *stt.StreamService

NewFluxSTT builds a Deepgram Flux streaming turn-aware STT service. Flux detects turn boundaries server-side, so the service recommends external user turns downstream.

func NewFluxTTS added in v0.1.0

func NewFluxTTS(cfg FluxTTSConfig) *tts.Base

NewFluxTTS builds a Deepgram Flux streaming WebSocket TTS service. A turn is synthesized as one Flux turn: the text is sent and flushed, and the returned PCM is streamed downstream.

The model's tokens are streamed straight through rather than grouped into sentences first, which is what Flux is for: synthesis starts on the first token instead of waiting for the sentence to finish. Call SetTextAggregator on the returned Base to group them into sentences instead, which reads more naturally at the cost of that wait.

func NewSTT

func NewSTT(cfg Config) *stt.StreamService

NewSTT builds a Deepgram streaming STT service.

func NewTTS

func NewTTS(cfg TTSConfig) *tts.Base

NewTTS builds a Deepgram Aura TTS service.

Types

type Config

type Config struct {
	// APIKey is the Deepgram API key. Required.
	APIKey string `validate:"required"`
	// BaseURL overrides the Deepgram host, for a private or air-gapped
	// deployment. It takes a host with an optional scheme, port and path, and the
	// scheme it carries decides whether the session is opened securely: "ws://"
	// or "http://" for an insecure one, "wss://" or "https://" for a secure one,
	// and a bare host for a secure one. Empty uses Deepgram's hosted API.
	BaseURL string
	// Model is the Deepgram model; empty uses "nova-3".
	Model string
	// Language is the transcription language; empty uses English (US).
	Language language.Language
	// SampleRate is the input audio sample rate; 0 uses the transport's rate.
	SampleRate int
	// Encoding is the audio encoding; empty uses "linear16".
	Encoding string
	// Channels is the channel count; 0 uses 1.
	Channels int

	// InterimResults emits partial transcripts; nil defaults to true.
	InterimResults *bool
	// SmartFormat applies Deepgram smart formatting; nil omits the param.
	SmartFormat *bool
	// Punctuate adds punctuation; nil defaults to true.
	Punctuate *bool
	// VADEvents requests Deepgram speech/utterance events; nil omits the param.
	VADEvents *bool
	// Endpointing is the silence in ms before Deepgram's speech_final; nil omits
	// the param.
	Endpointing *int
	// UtteranceEndMs is the silence in ms before an utterance-end event; nil omits
	// the param (jargo does not consume Deepgram's UtteranceEnd events).
	UtteranceEndMs *int

	// Numerals converts spoken numbers to numerals.
	Numerals *bool
	// ProfanityFilter filters profanity from transcripts.
	ProfanityFilter *bool
	// Diarize labels speakers in the transcript.
	Diarize *bool
	// DetectEntities enables named-entity detection.
	DetectEntities *bool
	// Dictation converts spoken commands (e.g. "comma") to punctuation.
	Dictation *bool
	// Multichannel transcribes each channel independently.
	Multichannel *bool
	// MipOptOut opts out of Deepgram's model-improvement program.
	MipOptOut *bool
	// Version pins the model version (e.g. "latest").
	Version string
	// Keywords boosts recognition of the given terms (legacy models); each entry
	// may carry an intensifier, e.g. "snuffleupagus:5".
	Keywords []string
	// Keyterm boosts recognition of the given terms (nova-3).
	Keyterm []string
	// Redact removes the given categories of sensitive data.
	Redact []string
	// Replace applies find/replace rules to the transcript.
	Replace []string
	// Search flags occurrences of the given terms.
	Search []string
	// Tag attaches billing tags to the request.
	Tag []string
	// ExtraQuery sets arbitrary additional Deepgram query parameters not modeled
	// above; values override any param of the same name set from other fields.
	ExtraQuery map[string]string

	// TTFSP99 overrides the measured transcript latency the turn strategies
	// size their wait by; 0 uses stt.DeepgramTTFSP99.
	TTFSP99 time.Duration
}

Config configures the STT service. Fields left at their zero value fall back to jargo's defaults (which preserve its tuned turn detection); several of those defaults differ from Deepgram's own and are noted per field. Optional fields modeled as pointers or slices are omitted from the request when unset.

func (Config) Validate

func (cfg Config) Validate() error

Validate reports whether the configuration is usable.

type FluxConfig added in v0.1.0

type FluxConfig struct {
	// ShouldInterrupt barges in when Flux detects that the user is speaking;
	// nil enables it. It is passed along to the user turn strategies this
	// service recommends, which own the interruption; strategies the application
	// configures itself override the recommendation and this setting with it.
	ShouldInterrupt *bool

	// APIKey is the Deepgram API key. Required.
	APIKey string `validate:"required"`
	// ListenURL overrides the transcription WebSocket endpoint; empty uses the
	// hosted endpoint.
	ListenURL string
	// Model is the Flux model; empty uses "flux-general-en". Set
	// "flux-general-multi" to enable language hints.
	Model string
	// SampleRate is the input audio sample rate; 0 uses the transport's rate.
	SampleRate int

	// EagerEOTThreshold enables eager end-of-turn predictions (interim
	// transcripts before a turn is confirmed). Off when nil.
	EagerEOTThreshold *float64
	// EOTThreshold is the end-of-turn confidence required to finish a turn;
	// nil uses the service default.
	EOTThreshold *float64
	// EOTTimeoutMs is the time in ms after speech to finish a turn regardless of
	// end-of-turn confidence; nil uses the service default.
	EOTTimeoutMs *int
	// MinConfidence drops a finalized turn whose average word confidence does
	// not exceed it; nil accepts every finalized turn.
	MinConfidence *float64
	// MipOptOut opts out of Deepgram's model-improvement program.
	MipOptOut *bool
	// Numerals writes spoken numbers as digits ("twenty three" becomes "23");
	// nil leaves the service default. Flux reads it only from the connection
	// URL, so changing it while the pipeline runs opens another connection.
	Numerals *bool
	// Keyterm boosts recognition of the given terms.
	Keyterm []string
	// Tag attaches billing tags to the request.
	Tag []string
	// LanguageHints biases detection toward the given languages. Only honored by
	// the multilingual model; ignored for other models.
	LanguageHints []language.Language
	// WatchdogMinTimeout is the minimum idle period before silence is injected
	// to keep an active turn from dangling; 0 uses 500ms.
	WatchdogMinTimeout time.Duration
	// ExtraQuery sets arbitrary additional query parameters; values override any
	// param of the same name set from other fields.
	ExtraQuery map[string]string
}

FluxConfig configures the Flux streaming turn-aware STT service. Fields left at their zero value fall back to the service defaults; optional tuning fields modeled as pointers or slices are omitted from the request when unset.

func (FluxConfig) Validate added in v0.1.0

func (cfg FluxConfig) Validate() error

Validate reports whether the configuration is usable.

type FluxSettings added in v0.2.0

type FluxSettings struct {
	// STT carries the model, which Flux reads only from the connection URL, so
	// a change to it is applied by opening another connection. It also carries a
	// language, which Flux has no parameter for: language_hints covers
	// multilingual input instead, so an update naming a language is reported as
	// unsupported.
	settings.STT

	// Numerals writes spoken numbers as digits. Read only from the connection
	// URL, so a change is applied by opening another connection.
	Numerals settings.Opt[bool] `settings:"numerals"`
	// Keyterm boosts recognition of the given terms.
	Keyterm settings.Opt[[]string] `settings:"keyterm"`
	// EOTThreshold is the end-of-turn confidence required to finish a turn.
	EOTThreshold settings.Opt[float64] `settings:"eot_threshold"`
	// EagerEOTThreshold is the confidence at which an eager end-of-turn is
	// predicted, ahead of the turn being confirmed.
	EagerEOTThreshold settings.Opt[float64] `settings:"eager_eot_threshold"`
	// EOTTimeoutMs is the time in ms after speech to finish a turn regardless of
	// end-of-turn confidence.
	EOTTimeoutMs settings.Opt[int] `settings:"eot_timeout_ms"`
	// LanguageHints biases detection toward the given languages, as the base
	// codes Flux takes. Only the multilingual model honors them. An empty list
	// clears whatever hints are in force.
	LanguageHints settings.Opt[[]string] `settings:"language_hints"`
	// MinConfidence drops a finalized turn whose average word confidence does
	// not exceed it. Applied to results as they arrive.
	MinConfidence settings.Opt[float64] `settings:"min_confidence"`
}

FluxSettings is the Flux configuration a caller may change while the pipeline runs. Which ones can be applied to a session already running is Flux's own division: some are sent to it, some are only read from the URL the connection opened with, and one is applied here to the results as they arrive.

type FluxTTSConfig added in v0.1.0

type FluxTTSConfig struct {
	// APIKey is the Deepgram API key. Required.
	APIKey string `validate:"required"`
	// SpeakURL overrides the synthesis WebSocket endpoint; empty uses the hosted
	// endpoint.
	SpeakURL string
	// Voice is the Flux voice identifier (e.g. "flux-alexis-en"); empty uses a
	// default. It is sent as Deepgram's "model" query parameter.
	Voice string
	// SampleRate is the PCM rate requested and emitted downstream; 0 uses 24 kHz.
	// A non-zero rate must be one of 8000, 16000, 24000, 32000, 44100, 48000.
	SampleRate int
	// MipOptOut opts out of Deepgram's model-improvement program.
	MipOptOut *bool
	// Tag attaches billing tags to the request.
	Tag []string
	// ExtraQuery sets arbitrary additional query parameters; values override any
	// param of the same name set from other fields.
	ExtraQuery map[string]string
}

FluxTTSConfig configures the Flux streaming TTS service. The audio is always linear16 (raw 16-bit little-endian mono PCM), the format the pipeline uses.

func (FluxTTSConfig) Validate added in v0.1.0

func (c FluxTTSConfig) Validate() error

Validate reports whether the configuration is usable.

type Settings added in v0.1.0

type Settings struct {
	settings.STT

	// DetectEntities enables named-entity detection.
	DetectEntities settings.Opt[bool] `settings:"detect_entities"`
	// Diarize labels speakers in the transcript.
	Diarize settings.Opt[bool] `settings:"diarize"`
	// Dictation converts spoken commands (e.g. "comma") to punctuation.
	Dictation settings.Opt[bool] `settings:"dictation"`
	// Endpointing is the silence in ms before Deepgram's speech_final.
	Endpointing settings.Opt[int] `settings:"endpointing"`
	// InterimResults emits partial transcripts.
	InterimResults settings.Opt[bool] `settings:"interim_results"`
	// Keyterm boosts recognition of the given terms (nova-3).
	Keyterm settings.Opt[[]string] `settings:"keyterm"`
	// Keywords boosts recognition of the given terms (legacy models).
	Keywords settings.Opt[[]string] `settings:"keywords"`
	// Numerals converts spoken numbers to numerals.
	Numerals settings.Opt[bool] `settings:"numerals"`
	// ProfanityFilter filters profanity from transcripts.
	ProfanityFilter settings.Opt[bool] `settings:"profanity_filter"`
	// Punctuate adds punctuation.
	Punctuate settings.Opt[bool] `settings:"punctuate"`
	// Redact removes the given categories of sensitive data.
	Redact settings.Opt[[]string] `settings:"redact"`
	// Replace applies find/replace rules to the transcript.
	Replace settings.Opt[[]string] `settings:"replace"`
	// Search flags occurrences of the given terms.
	Search settings.Opt[[]string] `settings:"search"`
	// SmartFormat applies Deepgram smart formatting.
	SmartFormat settings.Opt[bool] `settings:"smart_format"`
	// UtteranceEndMs is the silence in ms before an utterance-end event.
	UtteranceEndMs settings.Opt[int] `settings:"utterance_end_ms"`
}

Settings is the part of the Deepgram configuration that can change while the pipeline runs. It is the same set the provider itself treats as changeable; everything else about the connection, the endpoint, the encoding, the channel count, is fixed when the service is built.

A change to any of it reopens the transcription session, because Deepgram takes these as query parameters when the session opens and has no way to be told about them afterwards.

type TTSConfig

type TTSConfig struct {
	// APIKey is the Deepgram API key. Required.
	APIKey string `validate:"required"`
	// BaseURL overrides the Deepgram host, for a private or air-gapped
	// deployment. It is taken as given, scheme included; empty uses Deepgram's
	// hosted API.
	BaseURL string
	// Model is the Aura voice model; empty uses a default.
	Model string
	// SampleRate is the PCM rate requested from Aura and emitted downstream;
	// 0 uses 24 kHz.
	SampleRate int
	// Encoding is the audio encoding; empty uses "linear16".
	Encoding string
}

TTSConfig configures the Aura TTS service.

func (TTSConfig) Validate

func (c TTSConfig) Validate() error

Validate reports whether the configuration is usable.

Jump to

Keyboard shortcuts

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