Documentation
¶
Overview ¶
Package deepgram provides Deepgram's streaming speech-to-text service (over the live transcription WebSocket, see stt.go), its segmented speech-to-text service on the pre-recorded API, one request per speech segment (see segmented_stt.go), its Aura text-to-speech service over HTTP (see tts.go) and over the WebSocket API (see websocket_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
- func ForceEndTurn(svc *stt.StreamService) error
- func FormatPronunciation(word, ipa string) (string, bool)
- type BaseSTTSettings
- type Config
- type FluxConfig
- type FluxHTTPTTSConfig
- type FluxHTTPTTSService
- type FluxSTTService
- type FluxSettings
- type FluxTTSConfig
- type FluxTTSService
- type FluxTTSSettings
- type STTService
- type SegmentedSTTConfig
- type SegmentedSTTService
- type SegmentedSTTSettings
- type Settings
- type TTSConfig
- type TTSService
- type TTSSettings
- type WebsocketTTSConfig
- type WebsocketTTSService
Constants ¶
const ( // EventFluxStartOfTurn fires when Flux detects the user started a turn. The // transcript may hold the turn's first few words, or nothing. EventFluxStartOfTurn = "on_start_of_turn" // EventFluxTurnResumed fires when the user resumes speaking after a pause // Flux had predicted to be the end of the turn. EventFluxTurnResumed = "on_turn_resumed" // EventFluxEndOfTurn fires when Flux commits the end of the turn, with its // final transcript. EventFluxEndOfTurn = "on_end_of_turn" // EventFluxEagerEndOfTurn fires when Flux predicts the turn has ended // without committing to it, with the predicted transcript. EventFluxEagerEndOfTurn = "on_eager_end_of_turn" // EventFluxUpdate fires on each interim transcript of the turn in progress, // with the turn's transcript so far. An update with no text fires nothing. EventFluxUpdate = "on_update" )
The events the Flux STT service fires as Flux reports on the turn, each after the frames the report produced have been pushed. All but EventFluxTurnResumed carry the transcript Flux sent with the report.
The turn events follow Flux's turns. With FluxConfig.VADForceTurnEndpoint those are not the pipeline's turns: EventFluxEndOfTurn fires on every Flux finalization, so possibly several times per user turn. The user aggregator's own events report the pipeline's turns:
events.On(svc.Events(), deepgram.EventFluxUpdate,
func(ctx context.Context, transcript string) { … })
events.OnSignal(svc.Events(), deepgram.EventFluxTurnResumed,
func(ctx context.Context) { … })
Variables ¶
This section is empty.
Functions ¶
func ForceEndTurn ¶ added in v0.7.0
func ForceEndTurn(svc *stt.StreamService) error
ForceEndTurn asks Flux to finalize the audio svc has sent so far, ending the turn in progress, on a signal of the application's own such as a push-to-talk release. With VADForceTurnEndpoint each VAD stop does the same. Without it, the EndOfTurn Flux answers with ends the pipeline's turn as any other does.
It does nothing while no turn is in progress or no session is open, and fails when svc is not a Flux STT service or the request could not be sent.
func FormatPronunciation ¶ added in v0.3.0
FormatPronunciation renders a pronunciation as a Deepgram inline pronunciation object, e.g. \{"word": "dupilumab", "pronounce": "duːpˈɪljuːmæb"\}.
Aura-2 reads an escaped JSON object anywhere in the text and speaks its pronounce value in place of its word. The word stays in the text and is what Deepgram bills for; the IPA is not billed. English and Spanish only. Stress marks go directly before the vowel they stress; Aura-2 warns about any other placement and falls back to a best-effort pronunciation. It reports false for an empty pronunciation, or IPA longer than Deepgram accepts for the word.
Flux has no pronunciation markup, so the Flux service takes none; see https://developers.deepgram.com/docs/tts-voice-controls for which controls each model supports.
Types ¶
type BaseSTTSettings ¶ added in v1.0.0
type BaseSTTSettings struct {
settings.STT
// DetectEntities enables named-entity detection.
DetectEntities settings.Opt[bool] `settings:"detect_entities"`
// Diarize labels speakers in the transcript. The segmented service emits
// each contiguous speaker run of a result as its own frame, with Deepgram's
// speaker number ("0", "1", ...) as its speaker label.
Diarize settings.Opt[bool] `settings:"diarize"`
// Dictation converts spoken commands (e.g. "comma") to punctuation.
Dictation settings.Opt[bool] `settings:"dictation"`
// 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"`
// LanguageHint is one or more BCP-47 tags biasing language detection on
// Nova-3 multilingual. Deepgram ignores it unless the request sets model
// "nova-3" and language "multi", and rejects a tag the multilingual model
// does not cover.
LanguageHint settings.Opt[[]string] `settings:"language_hint"`
// 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"`
// RedactUsage stores keyterm, keywords, replace, search and extra as
// "[REDACTED]" in Deepgram's usage records, plus custom_topic and
// custom_intent on pre-recorded requests. Transcription and the response
// are unaffected.
RedactUsage settings.Opt[bool] `settings:"redact_usage"`
// 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"`
// Version is the model version to transcribe with, e.g. a dated
// standard-model version such as "2021-03-17.0" or a custom model's version
// id. No value omits the parameter, leaving Deepgram on "latest".
Version settings.Opt[string] `settings:"version"`
// SpeakerFormat formats each diarized speaker run: {speaker} is the
// speaker label, {text} the transcript text, and {speaker_number} the
// speaker's order of first appearance in the session (1, 2, ...), e.g.
// "{speaker}: {text}". No value leaves the text as it is. It is applied
// locally, so changing it does not reopen the session.
SpeakerFormat settings.Opt[string] `settings:"speaker_format"`
}
BaseSTTSettings is the settings both Deepgram speech-to-text APIs accept, streaming and pre-recorded. Settings and SegmentedSTTSettings embed it and add the settings only their own API accepts.
Model and Language come from settings.STT. On the segmented service, any other Deepgram request parameter can be passed through Extra, and a key of Extra that names one of the settings below sets that setting instead (see syncExtraToFields).
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
// RedactUsage stores keyterm, keywords, replace, search and the extra query
// parameters as "[REDACTED]" in Deepgram's usage records. Transcription is
// unaffected.
RedactUsage *bool
// 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; nil uses stt.DeepgramTTFSP99, and zero means no wait.
TTFSP99 *time.Duration
// Websocket configures the connection: whether and how it reconnects, and
// how long it waits on a peer that has stopped answering.
Websocket wsservice.Options
}
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.
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.
// Ignored with VADForceTurnEndpoint.
ShouldInterrupt *bool
// VADForceTurnEndpoint hands the decision of when a user turn ends to the
// pipeline's own user turn strategies (a smart-turn analyzer, an LLM
// completion gate), instead of Flux. Flux keeps transcribing: each
// VADUserStoppedSpeakingFrame asks it to finalize the audio sent so far
// with a ForceEndTurn, so a VAD analyzer is required, and one user turn can
// produce several finalized transcripts, which the user aggregator joins
// until the stop strategy ends the turn. The service then proposes neither
// turn edge and recommends no strategies. Flux still finalizes on its own
// confidence unless EOTThreshold is 1.0. It cannot be combined with
// EagerEOTThreshold: nothing answers Flux's predictions when the pipeline
// owns the turn. Off by default.
VADForceTurnEndpoint bool `validate:"excluded_with=EagerEOTThreshold"`
// TTFSP99 overrides the measured transcript latency the turn strategies
// size their wait by; nil uses stt.DeepgramFluxTTFSP99, and zero means no
// wait. It only applies with VADForceTurnEndpoint, where the transcript
// trails the VAD stop by a ForceEndTurn round trip; otherwise Flux marks
// the end of speech itself.
TTFSP99 *time.Duration
// 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. At 1.0 Flux ends a turn only on
// EOTTimeoutMs or a ForceEndTurn.
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. Changing it while the pipeline runs sends
// the change to the running 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. Nil uses 500ms; zero leaves only the
// floor of twice the last chunk's duration.
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
// Websocket configures the connection: whether and how it reconnects, and
// how long it waits on a peer that has stopped answering.
Websocket wsservice.Options
}
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 FluxHTTPTTSConfig ¶ added in v1.2.0
type FluxHTTPTTSConfig 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
// Voice is the Flux voice identifier (e.g. "flux-anjali-hi"); empty uses
// "flux-heather-en". It is sent as Deepgram's "model" query parameter, and
// is the model the synthesis is reported against.
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
// Speed multiplies the speaking rate, from 0.5 to 1.5 in steps of 0.05. Nil
// leaves Flux at its default rate.
Speed *float64 `validate:"omitempty,gte=0.5,lte=1.5"`
// Expressivity is the expressive range, on a calm (-2) to animated (2)
// axis. Nil leaves Flux at its default range.
Expressivity *int `validate:"omitempty,gte=-2,lte=2"`
// NormalizeVolume says whether Flux levels the loudness of the speech
// across voices and turns. Nil leaves Flux at its default, which levels it.
NormalizeVolume *bool
// MipOptOut opts out of the Deepgram Model Improvement Program. See
// https://dpgr.am/deepgram-mip for pricing impacts before setting it to
// true. Nil leaves it unset.
MipOptOut *bool
// Tag labels the requests for identification during usage reporting.
Tag []string
}
FluxHTTPTTSConfig configures the Flux TTS service over HTTP. The audio is always linear16 (raw 16-bit little-endian mono PCM), the format the pipeline uses.
func (FluxHTTPTTSConfig) Validate ¶ added in v1.2.0
func (c FluxHTTPTTSConfig) Validate() error
Validate reports whether the configuration is usable.
type FluxHTTPTTSService ¶ added in v1.2.0
FluxHTTPTTSService is the Deepgram text-to-speech service NewFluxHTTPTTS builds.
func NewFluxHTTPTTS ¶ added in v1.2.0
func NewFluxHTTPTTS(cfg FluxHTTPTTSConfig) *FluxHTTPTTSService
NewFluxHTTPTTS builds a Deepgram Flux TTS service over the batch HTTP API, issuing one request per sentence. Each request is independent, so there is no connection to manage and no acoustic state carried across turns: use NewFluxTTS for live conversations. It fits where a websocket TTS service does not, such as the caller voice in evals, including for languages that only have Flux voices, like Hindi.
The settings (FluxTTSSettings) can change while the pipeline runs; the next request is made with the new values.
type FluxSTTService ¶ added in v1.0.0
type FluxSTTService struct {
*stt.StreamService
}
FluxSTTService is the Deepgram speech-to-text service NewFluxSTT builds.
func NewFluxSTT ¶ added in v0.1.0
func NewFluxSTT(cfg FluxConfig) *FluxSTTService
NewFluxSTT builds a Deepgram Flux streaming turn-aware STT service. Flux detects turn boundaries server-side, so the service recommends external user turns downstream, unless VADForceTurnEndpoint hands the turns to the pipeline's own strategies.
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. A change is sent to the
// running 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-heather-en"); empty uses
// "flux-heather-en". It is sent as Deepgram's "model" query parameter, and
// is the model the synthesis is reported against.
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
// Speed multiplies the speaking rate, from 0.5 to 1.5 in steps of 0.05. Nil
// leaves Flux at its default rate. A change while the pipeline runs is
// applied to the open connection, so it keeps the acoustic state Flux holds
// across turns.
Speed *float64 `validate:"omitempty,gte=0.5,lte=1.5"`
// Expressivity is the expressive range, on a calm (-2) to animated (2)
// axis. Nil leaves Flux at its default range. Flux fixes it when the
// connection opens, so a change while the pipeline runs reconnects.
Expressivity *int `validate:"omitempty,gte=-2,lte=2"`
// NormalizeVolume says whether Flux levels the loudness of the speech
// across voices and turns. Nil leaves Flux at its default, which levels it.
// Fixed when the connection opens, so a change while the pipeline runs
// reconnects.
NormalizeVolume *bool
// 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
// Websocket configures the connection: whether and how it reconnects, and
// how long it waits on a peer that has stopped answering.
Websocket wsservice.Options
}
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 FluxTTSService ¶ added in v1.0.0
FluxTTSService is the Deepgram text-to-speech service NewFluxTTS builds.
func NewFluxTTS ¶ added in v0.1.0
func NewFluxTTS(cfg FluxTTSConfig) *FluxTTSService
NewFluxTTS builds a Deepgram Flux streaming WebSocket TTS service.
Flux keeps acoustic state across turns on a single connection, so prosody and pacing stay consistent throughout a conversation: the service opens one connection when the pipeline starts and speaks every turn on it, restoring it with backoff if it fails.
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.
Flux's inline pronunciation markup is early access and is refused with a fatal error on any connection whose speed is not 1.0, so the service formats no pronunciations: words given a pronunciation are spoken as written.
type FluxTTSSettings ¶ added in v0.6.0
type FluxTTSSettings struct {
settings.TTS
// Speed multiplies the speaking rate, from 0.5 to 1.5. No value leaves
// Flux at its default rate.
Speed settings.Opt[float64] `settings:"speed"`
// Expressivity is the expressive range, from -2 (calm) to 2 (animated). No
// value leaves Flux at its default range.
Expressivity settings.Opt[int] `settings:"expressivity"`
// NormalizeVolume says whether Flux levels the loudness of the speech. No
// value leaves Flux at its default, which levels it.
NormalizeVolume settings.Opt[bool] `settings:"normalize_volume"`
}
FluxTTSSettings is the part of the Flux synthesis configuration that can change while the pipeline runs.
The Flux voice is a single identifier (e.g. "flux-heather-en") carried by Voice. Deepgram takes it as its "model" query parameter, so Model follows Voice: it is what the synthesis is reported and priced against.
Speed is applied to the open connection with a Configure message. Every other setting is a query parameter fixed for the life of the connection, so a change to one reconnects.
func (*FluxTTSSettings) ApplyUpdate ¶ added in v0.6.0
func (s *FluxTTSSettings) ApplyUpdate(delta any) (settings.Changed, error)
ApplyUpdate merges an update and keeps the model in step with the voice, implementing settings.Updater. Deepgram takes the voice as the model, so a voice change is also reported as a model change, which relabels the synthesis the service reports from then on.
type STTService ¶ added in v1.0.0
type STTService struct {
*stt.StreamService
}
STTService is the Deepgram speech-to-text service NewSTT builds.
type SegmentedSTTConfig ¶ added in v1.0.0
type SegmentedSTTConfig struct {
// APIKey is the Deepgram API key. Required.
APIKey string `validate:"required"`
// BaseURL is the base URL of the Deepgram API, scheme included. Override it
// for a regional endpoint (e.g. "https://api.eu.deepgram.com") or a
// self-hosted deployment. Empty uses "https://api.deepgram.com".
BaseURL string
// SampleRate is the input audio sample rate; 0 uses the pipeline's rate.
SampleRate int
// Tag attaches custom billing tags to each request.
Tag []string
// MipOptOut opts out of Deepgram's Model Improvement Program; nil leaves it
// unset.
MipOptOut *bool
// Settings overrides the default settings, field by field: a field it does
// not give keeps its default, and one given no value (settings.Cleared)
// leaves the parameter out. Nil keeps every default: model
// "nova-3-general", language "en", punctuation on, and every other boolean
// setting off.
Settings *SegmentedSTTSettings
// HTTPClient makes the requests; nil uses one with the standard library's
// defaults. Supply one to set a timeout, a proxy, or connection limits of
// your own. The service sends through a copy of it, so the client itself
// is left as it is.
HTTPClient *http.Client
// TTFSP99 overrides the measured transcript latency the turn strategies
// size their wait by; nil uses stt.DefaultTTFSP99, and zero means no wait.
TTFSP99 *time.Duration
}
SegmentedSTTConfig configures the Deepgram segmented speech-to-text service, which transcribes each speech segment with one request to Deepgram's pre-recorded API.
func (SegmentedSTTConfig) Validate ¶ added in v1.0.0
func (c SegmentedSTTConfig) Validate() error
Validate reports whether the configuration is usable.
type SegmentedSTTService ¶ added in v1.0.0
type SegmentedSTTService struct {
*stt.SegmentService
}
SegmentedSTTService is the Deepgram speech-to-text service NewSegmentedSTT builds.
func NewSegmentedSTT ¶ added in v1.0.0
func NewSegmentedSTT(cfg SegmentedSTTConfig) *SegmentedSTTService
NewSegmentedSTT builds a Deepgram speech-to-text service on the pre-recorded API (POST /v1/listen) rather than a streaming WebSocket. It is segmented: the VAD upstream delimits each utterance, and each one is transcribed with one request carrying the audio as a WAV file. Transcripts are final only; there are no interim results.
Settings are read for every request, so an update applies from the next segment.
type SegmentedSTTSettings ¶ added in v1.0.0
type SegmentedSTTSettings struct {
BaseSTTSettings
// DetectLanguage detects the spoken language and transcribes in it,
// overriding Language. The detected language is reported on the transcript.
DetectLanguage settings.Opt[bool] `settings:"detect_language"`
// DiarizeModel is the diarization model Diarize turns on: "latest" or a
// version such as "v2". Diarization is requested with this parameter
// alone, since Deepgram's diarize parameter selects its oldest model and is
// refused alongside diarize_model.
DiarizeModel settings.Opt[string] `settings:"diarize_model"`
// FillerWords includes filler words such as "uh" and "um".
FillerWords settings.Opt[bool] `settings:"filler_words"`
}
SegmentedSTTSettings is the settings of the segmented service (see NewSegmentedSTT).
Each setting is sent as the Deepgram query parameter of the same name, except Diarize (see DiarizeModel) and the local SpeakerFormat, and a setting with no value is left out. Any other Deepgram pre-recorded query parameter can be passed through Extra.
type Settings ¶ added in v0.1.0
type Settings struct {
BaseSTTSettings
// 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"`
// 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 but the local SpeakerFormat 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
// Voice is the Aura voice model (e.g. "aura-2-helena-en"); empty uses
// "aura-2-helena-en". Deepgram takes it as its "model" query parameter, so
// it is also the model the synthesis is reported against.
Voice 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
// Speed multiplies the speaking rate, from 0.7 to 1.5. Nil leaves Aura at
// its default rate. Supported by the Aura-2 English and Spanish voices;
// Deepgram recommends staying at or above 0.9 for Spanish.
Speed *float64
// MipOptOut opts out of the Deepgram Model Improvement Program. See
// https://dpgr.am/deepgram-mip for pricing impacts before setting it to
// true. Nil leaves it unset.
MipOptOut *bool
}
TTSConfig configures the Aura TTS service over HTTP.
type TTSService ¶ added in v1.0.0
TTSService is the Deepgram text-to-speech service NewTTS builds.
func NewTTS ¶
func NewTTS(cfg TTSConfig) *TTSService
NewTTS builds a Deepgram Aura TTS service over HTTP, issuing one request per sentence. The voice and the speed can change while the pipeline runs (see TTSSettings); the next request is made with the new values.
type TTSSettings ¶ added in v0.7.0
type TTSSettings struct {
settings.TTS
// Speed multiplies the speaking rate, from 0.7 to 1.5.
Speed settings.Opt[float64] `settings:"speed"`
}
TTSSettings is the part of the Aura synthesis configuration that can change while the pipeline runs, for both the HTTP and the WebSocket service.
Voice is the Aura voice model. Deepgram takes it as its "model" query parameter, so Model follows Voice: it is what the synthesis is reported and priced against. Speed multiplies the speaking rate; no value leaves Aura at its default rate.
Every setting is a query parameter: the HTTP service sends the next request with the new values, and the WebSocket service reconnects.
func (*TTSSettings) ApplyUpdate ¶ added in v0.7.0
func (s *TTSSettings) ApplyUpdate(delta any) (settings.Changed, error)
ApplyUpdate merges an update and keeps the model in step with the voice, implementing settings.Updater. Deepgram takes the voice as the model, so a voice change is also reported as a model change, which relabels the synthesis the service reports from then on.
type WebsocketTTSConfig ¶ added in v0.7.0
type WebsocketTTSConfig struct {
// APIKey is the Deepgram API key. Required.
APIKey string `validate:"required"`
// BaseURL overrides the WebSocket base, scheme included; empty uses
// "wss://api.deepgram.com".
BaseURL string
// Voice is the Aura voice model (e.g. "aura-2-helena-en"); empty uses
// "aura-2-helena-en". Deepgram takes it as its "model" query parameter, so
// it is also the model the synthesis is reported against.
Voice string
// SampleRate is the audio rate requested from Aura and emitted downstream;
// 0 uses 24 kHz.
SampleRate int
// Encoding is the audio encoding: "linear16", "mulaw" or "alaw". Empty uses
// "linear16".
Encoding string
// Speed multiplies the speaking rate, from 0.7 to 1.5. Nil leaves Aura at
// its default rate. Supported by the Aura-2 English and Spanish voices;
// Deepgram recommends staying at or above 0.9 for Spanish.
Speed *float64
// MipOptOut opts out of the Deepgram Model Improvement Program. See
// https://dpgr.am/deepgram-mip for pricing impacts before setting it to
// true. Nil leaves it unset.
MipOptOut *bool
// Websocket configures the connection: whether and how it reconnects, and
// how long it waits on a peer that has stopped answering.
Websocket wsservice.Options
}
WebsocketTTSConfig configures the Aura TTS service over the WebSocket API.
func (WebsocketTTSConfig) Validate ¶ added in v0.7.0
func (c WebsocketTTSConfig) Validate() error
Validate reports whether the configuration is usable.
type WebsocketTTSService ¶ added in v1.0.0
WebsocketTTSService is the Deepgram text-to-speech service NewWebsocketTTS builds.
func NewWebsocketTTS ¶ added in v0.7.0
func NewWebsocketTTS(cfg WebsocketTTSConfig) *WebsocketTTSService
NewWebsocketTTS builds a Deepgram Aura TTS service over the WebSocket API. Unlike NewTTS, which issues one HTTP request per sentence, it holds one connection open for the call and streams each sentence on it, so no sentence pays for a connection before its audio starts.
The connection is opened when the pipeline starts. When it drops it is restored with backoff, and when that keeps failing the service reports a permanent error and becomes unusable. See tts.NewWebsocket.
Aura's audio names no request: it is labeled with the context playing, and frame handling pauses while a turn's audio is generated so turns never overlap. The text of a turn is generated once the turn has all been sent, and an interruption tells Aura to clear what it holds.