Documentation
¶
Overview ¶
Package nvidia provides NVIDIA services: an NVIDIA NIM OpenAI-compatible LLM (NewLLM), a Riva streaming speech-to-text service (NewSTT), and a Riva streaming text-to-speech service (NewTTS). Both speech services talk to NVIDIA's hosted endpoints or to a locally deployed Riva/NIM model (parakeet for recognition, magpie for synthesis), selected through the server address, the TLS setting, and the auth fields.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Endpointing ¶ added in v0.1.0
type Endpointing struct {
StartHistory *int32
StartThreshold *float32
StopHistory *int32
StopThreshold *float32
StopHistoryEOU *int32
StopThresholdEOU *float32
}
Endpointing tunes Riva's server-side start/end-of-utterance detector. Every field is optional; a nil field keeps the server's built-in default. The history fields are window sizes in milliseconds and the threshold fields are fractions in [0, 1].
type LLMService ¶ added in v1.0.0
type LLMService struct {
*chat.LLMService
}
LLMService is the NVIDIA LLM service NewLLM builds.
func NewLLM ¶
func NewLLM(cfg chat.LLMConfig) *LLMService
NewLLM builds an NVIDIA NIM LLM service.
Some models served by NIM reason before they answer, and the service keeps that reasoning off the answer, pushing it as thoughts so it is never spoken. A model that writes it into the answer text ahead of the answer, wrapped in <think> tags (DeepSeek-R1, some Nemotron models), has that leading block parsed out; one that streams it in a field of its own, reasoning_content (Nemotron Nano models), has the field read.
A local NIM takes no API key, so none is needed when BaseURL points at one. The cloud endpoint requires one, and a warning is logged without it.
type STTConfig ¶ added in v0.1.0
type STTConfig struct {
// Server is the Riva gRPC endpoint; empty uses NVIDIA's hosted endpoint. For
// a local NIM this is typically "localhost:50051".
Server string
// APIKey is the NVIDIA API key, sent as an "authorization: Bearer" header.
// Required by the hosted endpoint; omit for an unauthenticated local NIM.
APIKey string
// FunctionID is the NVIDIA Cloud Function id, sent as a "function-id" header.
// Required by the hosted endpoint to select the model; omit for a local NIM.
// It identifies one deployment of a model rather than the model itself, so
// it changes whenever NVIDIA redeploys; the current one is on the model's
// page under build.nvidia.com.
FunctionID string
// Model selects a served model by name; empty lets the server choose. A local
// Riva build usually serves one model, so this can stay empty.
Model string
// Language of the audio, mapped to a Riva BCP-47 code; the zero value uses US
// English.
Language language.Language
// SampleRate is the input audio sample rate; 0 uses the transport's rate.
SampleRate int
// UseSSL wraps the gRPC connection in TLS; nil defaults to true. Set to a
// pointer to false for a plaintext local NIM.
UseSSL *bool
// InterimResults requests tentative partial transcripts; nil defaults to true.
InterimResults *bool
// AutomaticPunctuation adds punctuation to results; nil defaults to true.
AutomaticPunctuation *bool
// VerbatimTranscripts disables inverse text normalization; nil defaults to
// true.
VerbatimTranscripts *bool
// ProfanityFilter masks profanities in the transcript.
ProfanityFilter bool
// MaxAlternatives caps the hypotheses returned per result; 0 uses 1.
MaxAlternatives int
// AudioChannelCount is the input channel count; 0 uses 1 (mono).
AudioChannelCount int
// CustomConfiguration passes request-level options to the model pipeline
// (for example "enable_vad_endpointing:true"), keyed by option name.
CustomConfiguration map[string]string
// Endpointing tunes the server-side utterance detector; nil uses the server
// defaults.
Endpointing *Endpointing
// BoostedLMWords are words boosted in the language model; empty boosts
// none.
BoostedLMWords []string
// BoostedLMScore is how much BoostedLMWords are boosted; nil uses 4.
BoostedLMScore *float64
// WordTimeOffsets includes word-level time offsets in the results.
WordTimeOffsets bool
// SpeakerDiarization tags each word with its speaker, pushing each
// contiguous speaker run of a final result as a transcript of its own
// (see STTSettings.SpeakerDiarization).
SpeakerDiarization bool
// MaxSpeakers caps the speakers diarization tells apart; 0 lets the server
// decide.
MaxSpeakers int
// SpeakerFormat formats each diarized speaker run (see
// STTSettings.SpeakerFormat); empty leaves the text as it is.
SpeakerFormat string
// TTFSP99 overrides the measured transcript latency the turn strategies
// size their wait by; nil uses stt.NvidiaTTFSP99, and zero means no wait.
TTFSP99 *time.Duration
}
STTConfig configures the NVIDIA Riva streaming speech-to-text service. The same service talks to NVIDIA's hosted ASR endpoint and to a locally deployed Riva/NIM model (such as parakeet); the deployment is selected entirely through Server, UseSSL, and the auth fields.
type STTService ¶ added in v1.0.0
type STTService struct {
*stt.StreamService
}
STTService is the NVIDIA Riva speech-to-text service NewSTT builds.
func NewSTT ¶ added in v0.1.0
func NewSTT(cfg STTConfig) *STTService
NewSTT builds an NVIDIA Riva streaming speech-to-text service. A finalized result (Riva's is_final, driven by server-side endpointing) marks the end of the user's turn.
type STTSettings ¶ added in v1.2.0
type STTSettings struct {
settings.STT
// ProfanityFilter masks profanities in the transcript.
ProfanityFilter settings.Opt[bool] `settings:"profanity_filter"`
// AutomaticPunctuation adds punctuation to results.
AutomaticPunctuation settings.Opt[bool] `settings:"automatic_punctuation"`
// VerbatimTranscripts disables inverse text normalization.
VerbatimTranscripts settings.Opt[bool] `settings:"verbatim_transcripts"`
// BoostedLMWords are words boosted in the language model.
BoostedLMWords settings.Opt[[]string] `settings:"boosted_lm_words"`
// BoostedLMScore is how much the boosted words are boosted.
BoostedLMScore settings.Opt[float64] `settings:"boosted_lm_score"`
// MaxAlternatives caps the hypotheses returned per result.
MaxAlternatives settings.Opt[int] `settings:"max_alternatives"`
// InterimResults requests tentative partial transcripts. They carry no
// word information, so they are never split by speaker.
InterimResults settings.Opt[bool] `settings:"interim_results"`
// WordTimeOffsets includes word-level time offsets in the results.
WordTimeOffsets settings.Opt[bool] `settings:"word_time_offsets"`
// SpeakerDiarization tags each word with its speaker. Each contiguous
// speaker run of a final result is then pushed as a transcript of its own,
// with NVIDIA's speaker tag (numbered from 1) as its label. A result with
// an untagged word, no word information, or words that cannot be located
// in its transcript is pushed whole, with no label.
SpeakerDiarization settings.Opt[bool] `settings:"speaker_diarization"`
// MaxSpeakers caps the speakers diarization tells apart; 0 lets the server
// decide. An update may also name it diarization_max_speakers, its former
// name.
MaxSpeakers settings.Opt[int] `settings:"max_speakers"`
// SpeakerFormat formats each diarized speaker run: {speaker} is the speaker
// tag, {text} the transcript text, and {speaker_number} the speaker's order
// of first appearance in the session (1, 2, ...). No value leaves the text
// as it is. Applied locally, so changing it does not reopen the stream.
SpeakerFormat settings.Opt[string] `settings:"speaker_format"`
}
STTSettings is the part of the streaming recognition configuration that can change while the pipeline runs. The stream is configured when it opens, so a change to anything but SpeakerFormat reopens it, once the user has stopped speaking.
func (STTSettings) Aliases ¶ added in v1.2.0
func (STTSettings) Aliases() map[string]string
Aliases maps the former name of max_speakers onto it.
type SegmentedSTTConfig ¶ added in v0.1.0
type SegmentedSTTConfig struct {
// Server is the Riva gRPC endpoint; empty uses NVIDIA's hosted endpoint. For
// a local NIM this is typically "localhost:50051".
Server string
// APIKey is the NVIDIA API key, sent as an "authorization: Bearer" header.
// Required by the hosted endpoint; omit for an unauthenticated local NIM.
APIKey string
// FunctionID is the NVIDIA Cloud Function id, sent as a "function-id" header.
// Required by the hosted endpoint to select the model; omit for a local NIM.
// It identifies one deployment of a model rather than the model itself, so
// it changes whenever NVIDIA redeploys; the current one is on the model's
// page under build.nvidia.com.
FunctionID string
// Model selects a served model by name; empty lets the server choose.
Model string
// Language of the audio, mapped to a Riva BCP-47 code; the zero value uses US
// English.
Language language.Language
// SampleRate is the input audio sample rate; 0 uses the transport's rate.
SampleRate int
// UseSSL wraps the gRPC connection in TLS; nil defaults to true. Set to a
// pointer to false for a plaintext local NIM.
UseSSL *bool
// AutomaticPunctuation adds punctuation to results; nil defaults to true.
AutomaticPunctuation *bool
// VerbatimTranscripts disables inverse text normalization; nil defaults to
// false, so numbers and dates come back written the usual way.
VerbatimTranscripts *bool
// ProfanityFilter masks profanities in the transcript.
ProfanityFilter bool
// MaxAlternatives caps the hypotheses returned per result; 0 uses 1.
MaxAlternatives int
// AudioChannelCount is the input channel count; 0 uses 1 (mono).
AudioChannelCount int
// CustomConfiguration passes request-level options to the model pipeline,
// keyed by option name.
CustomConfiguration map[string]string
// BoostedLMWords are words boosted in the language model; empty boosts
// none.
BoostedLMWords []string
// BoostedLMScore is how much BoostedLMWords are boosted; nil uses 4.
BoostedLMScore *float64
// WordTimeOffsets includes word-level time offsets in the results.
WordTimeOffsets bool
// SpeakerDiarization tags each word with its speaker, pushing each
// contiguous speaker run of a result as a transcript of its own (see
// STTSettings.SpeakerDiarization).
SpeakerDiarization bool
// MaxSpeakers caps the speakers diarization tells apart; 0 lets the server
// decide.
MaxSpeakers int
// SpeakerFormat formats each diarized speaker run (see
// STTSettings.SpeakerFormat); empty leaves the text as it is.
SpeakerFormat string
// TTFSP99 overrides the measured transcript latency the turn strategies
// size their wait by; nil uses stt.NvidiaTTFSP99, and zero means no wait.
TTFSP99 *time.Duration
}
SegmentedSTTConfig configures the NVIDIA Riva batch speech-to-text service. It transcribes one complete utterance per call against Riva's offline models, so it needs a turn detector upstream to delimit each segment.
func (SegmentedSTTConfig) Validate ¶ added in v0.1.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 NVIDIA Riva speech-to-text service NewSegmentedSTT builds.
func NewSegmentedSTT ¶ added in v0.1.0
func NewSegmentedSTT(cfg SegmentedSTTConfig) *SegmentedSTTService
NewSegmentedSTT builds an NVIDIA Riva batch speech-to-text service. It transcribes each utterance in one call once a turn detector upstream has delimited it, unlike NewSTT which streams continuously. Use it with Riva's offline models, which are more accurate but produce no interim transcripts.
type SegmentedSTTSettings ¶ added in v1.2.0
type SegmentedSTTSettings struct {
settings.STT
// ProfanityFilter masks profanities in the transcript.
ProfanityFilter settings.Opt[bool] `settings:"profanity_filter"`
// AutomaticPunctuation adds punctuation to results.
AutomaticPunctuation settings.Opt[bool] `settings:"automatic_punctuation"`
// VerbatimTranscripts disables inverse text normalization.
VerbatimTranscripts settings.Opt[bool] `settings:"verbatim_transcripts"`
// BoostedLMWords are words boosted in the language model.
BoostedLMWords settings.Opt[[]string] `settings:"boosted_lm_words"`
// BoostedLMScore is how much the boosted words are boosted.
BoostedLMScore settings.Opt[float64] `settings:"boosted_lm_score"`
// MaxAlternatives caps the hypotheses returned per result.
MaxAlternatives settings.Opt[int] `settings:"max_alternatives"`
// WordTimeOffsets includes word-level time offsets in the results.
WordTimeOffsets settings.Opt[bool] `settings:"word_time_offsets"`
// SpeakerDiarization tags each word with its speaker, pushing each
// contiguous speaker run of a result as a transcript of its own (see
// STTSettings.SpeakerDiarization).
SpeakerDiarization settings.Opt[bool] `settings:"speaker_diarization"`
// MaxSpeakers caps the speakers diarization tells apart; 0 lets the server
// decide. An update may also name it diarization_max_speakers.
MaxSpeakers settings.Opt[int] `settings:"max_speakers"`
// SpeakerFormat formats each diarized speaker run (see
// STTSettings.SpeakerFormat).
SpeakerFormat settings.Opt[string] `settings:"speaker_format"`
}
SegmentedSTTSettings is the part of the batch recognition configuration that can change while the pipeline runs. Every utterance is its own request, so a change applies from the next one.
func (SegmentedSTTSettings) Aliases ¶ added in v1.2.0
func (SegmentedSTTSettings) Aliases() map[string]string
Aliases maps the former name of max_speakers onto it.
type SynthesisMode ¶ added in v1.2.0
type SynthesisMode string
SynthesisMode is how text is sent to the synthesizer.
const ( // SynthesisModePerSentence opens a SynthesizeOnline call for each request // a sentence is split into. Every model takes it. SynthesisModePerSentence SynthesisMode = "per_sentence" // SynthesisModeStitched sends every sentence of a reply on one // SynthesizeOnline stream, which the models that stitch across sentences // (Magpie multilingual and Magpie zero-shot 1.7.0 and later) speak as one // utterance. Use it only with such a model. SynthesisModeStitched SynthesisMode = "stitched" )
type TTSConfig ¶ added in v0.1.0
type TTSConfig struct {
// Server is the Riva gRPC endpoint; empty uses NVIDIA's hosted endpoint. For
// a local NIM this is typically "localhost:50051".
Server string
// APIKey is the NVIDIA API key, sent as an "authorization: Bearer" header.
// Required by the hosted endpoint; omit for an unauthenticated local NIM.
APIKey string
// FunctionID is the NVIDIA Cloud Function id, sent as a "function-id" header.
// It selects the model on the hosted endpoint; empty uses the multilingual
// Magpie function. Set it to "-" to send no function id, as a local NIM
// expects.
FunctionID string
// Model names the served model. It labels the metrics and traces and is what
// a cost-tracking backend prices against; empty uses the hosted default. It
// does not select the model, FunctionID does.
Model string
// Voice is the voice name; empty uses a multilingual Magpie voice.
Voice string
// Language for synthesis, mapped to a Riva BCP-47 code; the zero value uses
// US English.
Language language.Language
// SampleRate is the PCM rate requested from the server and emitted
// downstream; 0 uses 24 kHz. Rates below 8 kHz do not produce usable audio.
SampleRate int
// UseSSL wraps the gRPC connection in TLS; nil defaults to true. Set to a
// pointer to false for a plaintext local NIM.
UseSSL *bool
// CustomDictionary maps a written form to its IPA pronunciation, for example
// {"NVIDIA": "ɛn.vɪ.diː.ʌ"}; empty sends none.
CustomDictionary map[string]string
// CustomConfiguration passes model-specific options the schema does not name
// (for example "exaggeration_factor"), keyed by option name.
CustomConfiguration map[string]string
// ZeroShot supplies the voice-cloning prompt a zero-shot model needs; nil
// omits it, which is what every other model expects.
ZeroShot *ZeroShot `validate:"omitempty"`
// SynthesisMode is how the text is sent; empty uses
// SynthesisModePerSentence, which every model takes.
SynthesisMode SynthesisMode `validate:"omitempty,oneof=per_sentence stitched"`
}
TTSConfig configures the NVIDIA Riva streaming text-to-speech service. The same service talks to NVIDIA's hosted TTS endpoint and to a locally deployed Riva/NIM model; the deployment is selected entirely through Server, UseSSL, and the auth fields. The voice, the language, the zero-shot quality and the custom configuration may also be changed while the pipeline runs (see TTSSettings).
type TTSService ¶ added in v1.0.0
TTSService is the NVIDIA Riva text-to-speech service NewTTS builds.
func NewTTS ¶ added in v0.1.0
func NewTTS(cfg TTSConfig) *TTSService
NewTTS builds an NVIDIA Riva streaming text-to-speech service. The text of a sentence is split when the model's request-length limit requires it. With SynthesisModePerSentence each piece is its own SynthesizeOnline call, whose audio is streamed downstream; with SynthesisModeStitched every sentence of a reply goes on one SynthesizeOnline stream, which ends with the reply.
type TTSSettings ¶ added in v1.2.0
type TTSSettings struct {
settings.TTS
// Quality is how many times a zero-shot prompt passes through the decoder,
// 1 to 40. It applies only with a zero-shot prompt (see TTSConfig.ZeroShot).
Quality settings.Opt[int] `settings:"quality"`
// CustomConfiguration passes model-specific options the schema does not
// name, such as Magpie's streaming controls or Chatterbox's
// "exaggeration_factor", keyed by option name.
CustomConfiguration settings.Opt[map[string]string] `settings:"custom_configuration"`
// SynthesisMode is how the text is sent (see TTSConfig.SynthesisMode). A
// change applies from the next reply.
SynthesisMode settings.Opt[SynthesisMode] `settings:"synthesis_mode"`
}
TTSSettings is the part of the synthesis configuration that can change while the pipeline runs. Every sentence, or every reply when stitched, opens a synthesis of its own, so a change applies from the next one.
type ZeroShot ¶ added in v0.1.0
type ZeroShot struct {
// AudioPrompt is the prompt audio. NVIDIA recommends 16-bit mono, 22.05 kHz
// or higher, and 3 to 10 seconds long. Required.
AudioPrompt []byte `validate:"required,min=1"`
// Encoding of the prompt, either "pcm" (the default) or "oggopus".
Encoding string `validate:"omitempty,oneof=pcm oggopus"`
// SampleRate of the prompt; 0 lets the server assume 22050.
SampleRate int
// Quality is how many times the prompt passes through the decoder, 1 to 40;
// 0 uses 20.
Quality int `validate:"omitempty,min=1,max=40"`
// Transcript of the prompt audio; empty sends none.
Transcript string
}
ZeroShot supplies the audio prompt a zero-shot model clones its voice from. Access to NVIDIA's hosted zero-shot models needs approval.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
rivapb
Package rivapb holds the generated gRPC clients for the subset of the NVIDIA Riva speech API the streaming ASR and TTS services use.
|
Package rivapb holds the generated gRPC clients for the subset of the NVIDIA Riva speech API the streaming ASR and TTS services use. |