Documentation
¶
Overview ¶
Package smallest provides Smallest AI's services: Electron, its LLM, over the Waves API's OpenAI-compatible endpoint; Pulse streaming speech-to-text; and streaming text-to-speech over the Waves WebSocket.
The text-to-speech service holds one connection open for the call, sends the sentences of a turn on the turn's continuation context so they are spoken as one generation, and labels the audio that comes back with the context playing, since Smallest's messages name no request.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// APIKey is the Smallest AI API key. Required.
APIKey string `validate:"required"`
// URL overrides the TTS WebSocket endpoint; empty uses the hosted endpoint.
URL string
// Model is the Smallest model id; empty uses a default.
Model string
// Voice is the voice id; empty uses a default voice.
Voice string
// Language is the synthesis language code; empty uses "en".
Language string
// SampleRate is the PCM rate requested and emitted downstream; 0 uses 24 kHz.
SampleRate int
// OutputFormat is the audio format Smallest returns: "pcm", "mp3", "wav",
// "ulaw" or "alaw". Empty uses "pcm", which is what the pipeline carries.
OutputFormat string `validate:"omitempty,oneof=pcm mp3 wav ulaw alaw"`
// WordTimestamps asks for the timing of each word, so the text of each word
// is pushed as its audio plays and an interruption leaves the context with
// only what was heard. Nil turns it on. Voices that do not report word
// timing send none, which leaves it harmless to keep on whatever the voice.
WordTimestamps *bool
// MaxBufferDelayMs bounds, in milliseconds (0 to 5000), how long the server
// buffers a fragment of a turn before speaking it. Nil leaves the server's
// default, 3000.
MaxBufferDelayMs *int `validate:"omitempty,gte=0,lte=5000"`
// Speed multiplies the speaking rate; nil uses the service default.
Speed *float64
// MathNotation reads a math operator between digits as a word, so "2 + 2" is
// spoken as "two plus two" rather than left to the default number reader; nil
// leaves the API's own default, which is off.
MathNotation *bool
// ContentFilter checks the text against Smallest's profanity word list
// before synthesis, taking this action on a match: "reject" fails the
// request with a CONTENT_FILTER_BLOCKED error and synthesizes nothing;
// "flag" synthesizes normally and records the match; "redact" drops the
// matched term and speaks the rest, failing like "reject" when nothing is
// left to speak. Empty leaves the API default, which is off.
ContentFilter string
// DateFormat is the order all-numeric dates are read in, independent of the
// synthesis voice: "EU" reads 05/03/2024 day-first ("fifth March, twenty
// twenty four"), "US" month-first ("May third, twenty twenty four"). Empty
// leaves the API default, "US".
DateFormat string
// NumberPronunciationLanguage is the language code numerals, currency,
// times and dates are read in, independent of the synthesis language.
// Empty reads them in the synthesis language.
NumberPronunciationLanguage 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
}
Config configures the Smallest AI TTS service.
type LLMConfig ¶ added in v0.7.0
type LLMConfig struct {
chat.LLMConfig
// PromptCacheKey groups the requests of one conversation, so each turn is
// served where that conversation is already cached. Use a fresh value per
// conversation and never share one between conversations. Empty sends none.
PromptCacheKey string
}
LLMConfig configures a Smallest AI LLM service: everything the OpenAI-compatible endpoint takes, plus the prompt cache key Electron adds to it. The model defaults to Electron.
type LLMService ¶ added in v1.0.0
type LLMService struct {
*chat.LLMService
}
LLMService is the Smallest AI LLM service NewLLM builds.
func NewLLM ¶ added in v0.7.0
func NewLLM(cfg LLMConfig) *LLMService
NewLLM builds a Smallest AI LLM service over the Waves API's OpenAI-compatible endpoint, defaulting to Electron.
Electron does not support the developer role, so a developer message is sent as a user message. Smallest's source identification header is always sent, over the caller's own headers.
type LLMSettings ¶ added in v0.7.0
type LLMSettings struct {
chat.LLMSettings
// PromptCacheKey groups the requests of one conversation; unset sends none.
PromptCacheKey settings.Opt[string] `settings:"prompt_cache_key"`
}
LLMSettings is the Smallest AI LLM configuration that can change while the pipeline runs, through an LLMUpdateSettingsFrame: the OpenAI-compatible settings, plus the prompt cache key.
type STTConfig ¶
type STTConfig struct {
// APIKey is the Smallest AI API key. Required.
APIKey string `validate:"required"`
// BaseURL overrides the STT WebSocket base; empty uses the hosted endpoint.
BaseURL string
// Model is the transcription model; empty uses "pulse". "pulse-2" is
// English-only and adds a per-utterance emotion and gender to final
// transcripts.
Model string
// Language is the audio language code; empty uses English. A regional
// variant is sent by its base code.
Language string
// Encoding is the PCM encoding sent to the API; empty uses "linear16".
Encoding string
// SampleRate is the input audio sample rate; 0 uses the transport's rate.
SampleRate int
// WordTimestamps asks for word-level timings on each transcript.
WordTimestamps bool
// FullTranscript asks each message to carry the transcript so far rather
// than only what is new.
FullTranscript bool
// SentenceTimestamps asks for sentence-level timings on each transcript.
SentenceTimestamps bool
// RedactPII redacts personally identifiable information.
RedactPII bool
// RedactPCI redacts payment card information.
RedactPCI bool
// Numerals writes spoken numbers as digits; empty uses "auto".
Numerals string
// Diarize splits each final transcript into one transcript per contiguous
// speaker run, labeled with Smallest's speaker number. It asks for word
// timestamps, which carry the speakers. Interim transcripts carry none.
Diarize bool
// Endpointing finalizes a transcript promptly on trailing silence; nil
// defaults to true.
Endpointing *bool
// EOUTimeoutMs is the trailing silence, in ms from 100 to 10000, before
// Pulse finalizes a transcript on its own; nil leaves the server's default
// (600 with endpointing, 800 without). The VAD's finalize already ends the
// last segment of a turn, so it governs the pauses inside one. pulse-2
// ignores it.
EOUTimeoutMs *int
// Keywords biases recognition towards domain terms, as comma-separated
// KEYWORD:INTENSIFIER pairs (e.g. "NVIDIA:2"). Empty sends none, since an
// empty value would register one empty keyword.
Keywords string
// Format punctuates and capitalizes the transcripts; nil defaults to true.
Format *bool
// EmotionDetection and GenderDetection add a per-utterance emotion and
// gender estimate to every final transcript of pulse-2; nil enables each.
// Pulse ignores them.
EmotionDetection *bool
GenderDetection *bool
// ITNNormalize writes spoken numbers as digits ("twenty five" as "25").
ITNNormalize bool
// NoFormatDelay emits every final as soon as it is ready. Otherwise, with
// ITNNormalize, a number still being dictated at the end of a final is
// held back and merged into the next one so it normalizes whole.
NoFormatDelay bool
// 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 (1, 2, ...), e.g. "{speaker}: {text}". Empty leaves
// the text as it is. It is applied here, never sent.
SpeakerFormat string
// TTFSP99 overrides the measured transcript latency the turn strategies
// size their wait by; nil uses stt.SmallestTTFSP99, 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 Smallest AI streaming STT (Pulse) service. The model, the language and the transcription fields are the starting settings, which can change while the pipeline runs (see STTSettings).
type STTService ¶ added in v1.0.0
type STTService struct {
*stt.StreamService
}
STTService is the Smallest AI speech-to-text service NewSTT builds.
func NewSTT ¶
func NewSTT(cfg STTConfig) *STTService
NewSTT builds a Smallest AI streaming STT service. The pipeline's VAD ends each utterance by asking Pulse to finalize it, and the session stays open for the next one.
type STTSettings ¶ added in v1.2.0
type STTSettings struct {
settings.STT
WordTimestamps settings.Opt[bool] `settings:"word_timestamps"`
FullTranscript settings.Opt[bool] `settings:"full_transcript"`
SentenceTimestamps settings.Opt[bool] `settings:"sentence_timestamps"`
RedactPII settings.Opt[bool] `settings:"redact_pii"`
RedactPCI settings.Opt[bool] `settings:"redact_pci"`
Numerals settings.Opt[string] `settings:"numerals"`
Diarize settings.Opt[bool] `settings:"diarize"`
Endpointing settings.Opt[bool] `settings:"endpointing"`
EOUTimeoutMs settings.Opt[int] `settings:"eou_timeout_ms"`
Keywords settings.Opt[string] `settings:"keywords"`
Format settings.Opt[bool] `settings:"format"`
EmotionDetection settings.Opt[bool] `settings:"emotion_detection"`
GenderDetection settings.Opt[bool] `settings:"gender_detection"`
ITNNormalize settings.Opt[bool] `settings:"itn_normalize"`
NoFormatDelay settings.Opt[bool] `settings:"no_format_delay"`
SpeakerFormat settings.Opt[string] `settings:"speaker_format"`
}
STTSettings is what can change while the pipeline runs. Pulse reads all of it when a connection opens, so a change reopens the session, except to the speaker format, which is applied here to the transcripts. The fields are described on STTConfig.
type TTSService ¶ added in v1.0.0
TTSService is the Smallest AI text-to-speech service NewTTS builds.
func NewTTS ¶
func NewTTS(cfg Config) *TTSService
NewTTS builds a Smallest AI TTS service.
It holds one connection open for the call, 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. Smallest's audio names no request, so an interruption while the bot speaks resets the connection, and the next request's frames are held until this one's audio has played. See tts.NewInterruptibleWebsocket.
type TTSSettings ¶ added in v0.6.0
type TTSSettings struct {
settings.TTS
// Speed multiplies the speaking rate (0.5 to 2.0).
Speed settings.Opt[float64] `settings:"speed"`
// MathNotation reads a math operator between digits as a word.
MathNotation settings.Opt[bool] `settings:"math_notation"`
// ContentFilter is the action taken on text that matches Smallest's
// profanity word list: "reject", "flag" or "redact".
ContentFilter settings.Opt[string] `settings:"content_filter"`
// DateFormat is the order all-numeric dates are read in: "EU" or "US".
DateFormat settings.Opt[string] `settings:"date_format"`
// NumberPronunciationLanguage is the language code numerals, currency,
// times and dates are read in.
NumberPronunciationLanguage settings.Opt[string] `settings:"number_pronunciation_language"`
}
TTSSettings is the part of the synthesis configuration that can change while the pipeline runs.
Every request carries the settings it is spoken with, so a change takes effect on the next request, without reconnecting. Those left without a value are left to Smallest.