Documentation
¶
Overview ¶
Package gradium provides Gradium's speech services: streaming text-to-speech and real-time streaming speech-to-text, both over Gradium's WebSocket API. The TTS side holds one connection open for the call and speaks each turn as a request of its own on it, streaming the raw PCM audio downstream with the time each word is spoken; the STT side streams 80 ms audio chunks and surfaces recognized text as interim and finalized transcriptions.
Index ¶
Constants ¶
const ( // EventTurnStart fires when the end-pointing signal opens a turn. EventTurnStart = "on_turn_start" // EventTurnEnd fires when the end-pointing signal closes the turn. EventTurnEnd = "on_turn_end" )
Events a Gradium STT service raises with turn detection on, each with the service as its source.
const AnyLanguage language.Language = "any"
AnyLanguage asks Gradium to detect the language rather than being grounded in one. It is not one of the language constants because it names a mode rather than a language, and it is passed through as it is written.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LogLevel ¶ added in v0.7.0
type LogLevel string
LogLevel is the lowest level of the server's log messages a session asks for. The server reports problems with the session's setup this way, such as an unknown or deprecated json_config key, and the session carries on.
type STTConfig ¶
type STTConfig struct {
// APIKey is the Gradium API key, sent as the x-api-key header. Required.
APIKey string `validate:"required"`
// URL overrides the ASR WebSocket endpoint; empty uses the hosted endpoint.
URL string
// Model is the transcription model; empty uses a default.
Model string
// Encoding is the base audio encoding ("pcm", "wav", or "opus"); empty uses
// "pcm". For PCM the sample rate is appended to form the input format (for
// example "pcm_16000"). Audio at a rate Gradium does not accept is resampled
// to one it does.
Encoding string
// Language grounds the transcription in one language; the zero value uses
// English. Verified codes are de, en, es, fr, and pt; other languages fall
// back to the base code. Set it to AnyLanguage to have Gradium detect the
// language instead.
Language language.Language
// SampleRate is the input audio sample rate; 0 uses the transport's rate.
SampleRate int
// DelayInFrames delays text generation by this many 80 ms frames; nil uses a
// default. Allowed values: 7, 8, 10, 12, 14, 16, 20, 24, 36, 48.
DelayInFrames *int `validate:"omitempty,oneof=7 8 10 12 14 16 20 24 36 48"`
// LogLevel opts in to the server's log messages, such as a warning about an
// unknown or deprecated setting: the lowest level to receive. They are logged
// at their own level. Empty asks for none, the default.
LogLevel LogLevel `validate:"omitempty,oneof=debug info warning error"`
// EnableTurnDetection lets Gradium's end-pointing signal decide when user
// turns start and end, instead of the pipeline's VAD. The service then
// proposes each turn's start and end, flushes the server at the end of a
// turn, and recommends the external turn strategies, which resolve the
// proposals into the user's turn. Off by default.
EnableTurnDetection bool
// EOTHorizonS picks the end-pointing horizon that drives turn decisions:
// the step entry whose horizon is closest to it is watched. Nil uses 3
// seconds with turn detection on.
EOTHorizonS *float64
// EOTThreshold is the inactivity probability on that horizon at or above
// which an open turn ends, and below which a turn opens once the signal has
// read inactive. Nil uses 0.5 with turn detection on.
EOTThreshold *float64
// PostFlushCooldownFrames is how many step messages to ignore after a flush
// before the next turn may start or end. A flush feeds the model silence,
// and the signal is unreliable on the frames that follow: it can dip as if
// speech resumed, then fire again on the first real frames. Nil uses 8 with
// turn detection on.
PostFlushCooldownFrames *int
// TTFSP99 overrides the measured transcript latency the turn strategies
// size their wait by; nil uses stt.GradiumTTFSP99, 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
}
STTConfig configures the Gradium STT service.
type STTService ¶ added in v1.0.0
type STTService struct {
*stt.StreamService
}
STTService is the Gradium speech-to-text service NewSTT builds.
func NewSTT ¶
func NewSTT(cfg STTConfig) *STTService
NewSTT builds a Gradium streaming STT service.
It transcribes English unless the configuration names another language. Set Language to AnyLanguage to have Gradium detect it instead.
By default the pipeline's VAD closes each utterance: when it reports the user stopped, the server is flushed and the text gathered finalizes into the transcript. With EnableTurnDetection the server's end-pointing signal drives the turns instead, and the VAD is left to the turn strategies.
type STTSettings ¶ added in v0.7.0
type STTSettings struct {
settings.STT
// DelayInFrames delays text generation by this many 80 ms frames.
DelayInFrames settings.Opt[int] `settings:"delay_in_frames"`
// EOTHorizonS picks the end-pointing horizon that drives turn decisions.
EOTHorizonS settings.Opt[float64] `settings:"eot_horizon_s"`
// EOTThreshold is the inactivity probability that opens and ends a turn.
EOTThreshold settings.Opt[float64] `settings:"eot_threshold"`
// PostFlushCooldownFrames is how many step messages to ignore after a flush.
PostFlushCooldownFrames settings.Opt[int] `settings:"post_flush_cooldown_frames"`
}
STTSettings is the part of the Gradium STT configuration that can change while the pipeline runs. The model, the language and the decoder delay are bound to the session's setup message, so a change to any of them reopens the session. The turn detection fields are read as step messages arrive and take effect on the next one.
type TTSConfig ¶
type TTSConfig struct {
// APIKey is the Gradium API key, sent as the x-api-key header. Required.
APIKey string `validate:"required"`
// URL overrides the TTS WebSocket endpoint; empty uses the hosted endpoint.
URL string
// VoiceID is the voice identifier; empty uses a default voice.
VoiceID string
// JSONConfig is an optional JSON configuration string forwarded to the model;
// empty omits it.
JSONConfig string
// LogLevel opts in to the server's log messages, such as a warning about an
// unknown or deprecated JSONConfig key: the lowest level to receive. They
// are logged at their own level. Empty asks for none, the default.
LogLevel LogLevel `validate:"omitempty,oneof=debug info warning error"`
// Websocket configures the connection: whether and how it reconnects, and
// how long it waits on a peer that has stopped answering.
Websocket wsservice.Options
}
TTSConfig configures the Gradium TTS service.
type TTSService ¶ added in v1.0.0
TTSService is the Gradium text-to-speech service NewTTS builds.
func NewTTS ¶
func NewTTS(cfg TTSConfig) *TTSService
NewTTS builds a Gradium TTS service. It holds one connection open for the call, restoring it with backoff if it fails, and speaks each turn on a request of its own on that connection.
type TTSSettings ¶ added in v0.6.0
TTSSettings is the part of the synthesis configuration that can change while the pipeline runs. A new voice reconnects, so every context opened after it is set up with it. The model and the language are not sent to Gradium, so a change to either is stored and warned about.