Documentation
¶
Overview ¶
Package stt defines the SpeechKit speech-to-text provider interface and houses the concrete provider implementations: whisper.cpp (local built-in), HuggingFace, OpenAI, Groq, Google, an OpenAI-compatible adapter (covers Ollama and other compatible servers), and the self-hosted VPS adapter.
All providers must go through github.com/kombifyio/SpeechKit/pkg/speechkit/netsec for outbound HTTP. Routing — which provider to pick for a given request — is the host's responsibility (a routing/fallback layer above these providers).
Index ¶
- Constants
- func AsTranscriber(p STTProvider, opts ...TranscriberOption) speechkit.Transcriber
- func FindWhisperBinary() (string, error)
- func IsMultilanguage(language string) bool
- func ParseDeepgramKeyterms(raw string) []string
- func SetSecretResolver(fn func(string) string)
- func SetSubprocessPriorityLowered(bool)
- func ToTranscript(r *Result, durationSecs float64) speechkit.Transcript
- func ValidateModelPath(path string) error
- type AssemblyAIProvider
- func (*AssemblyAIProvider) Capabilities() []speechkit.Capability
- func (p *AssemblyAIProvider) EnableStreamingLLM(model, prompt string, maxTokens int)
- func (p *AssemblyAIProvider) Health(ctx context.Context) error
- func (p *AssemblyAIProvider) Name() string
- func (p *AssemblyAIProvider) StartDictationStream(ctx context.Context, opts speechkit.DictationStreamOptions, ...) (speechkit.DictationStream, error)
- func (p *AssemblyAIProvider) StartSpeakerStream(ctx context.Context, opts speaker.Options, format speaker.AudioFormat) (speaker.SpeakerStream, error)
- func (p *AssemblyAIProvider) Transcribe(ctx context.Context, audio []byte, opts TranscribeOpts) (*Result, error)
- func (p *AssemblyAIProvider) Warm(ctx context.Context) error
- type AssemblyAIStreamingLLM
- type CapabilityReporter
- type DeepgramOptions
- type DeepgramProvider
- func (p *DeepgramProvider) ApplyOptions(opts DeepgramOptions)
- func (*DeepgramProvider) Capabilities() []speechkit.Capability
- func (p *DeepgramProvider) Health(ctx context.Context) error
- func (p *DeepgramProvider) Name() string
- func (p *DeepgramProvider) StartDictationStream(ctx context.Context, opts speechkit.DictationStreamOptions, ...) (speechkit.DictationStream, error)
- func (p *DeepgramProvider) StartFluxTurnStream(ctx context.Context, opts FluxStreamOptions, format speaker.AudioFormat) (*FluxTurnStream, error)
- func (p *DeepgramProvider) StartSpeakerStream(ctx context.Context, opts speaker.Options, format speaker.AudioFormat) (speaker.SpeakerStream, error)
- func (p *DeepgramProvider) Transcribe(ctx context.Context, audio []byte, opts TranscribeOpts) (*Result, error)
- type FluxStreamOptions
- type FluxTurn
- type FluxTurnStream
- type FluxWord
- type GoogleSTTProvider
- func (*GoogleSTTProvider) Capabilities() []speechkit.Capability
- func (p *GoogleSTTProvider) Health(ctx context.Context) error
- func (p *GoogleSTTProvider) Name() string
- func (p *GoogleSTTProvider) SetStreamingCredentialEnvs(credentialsJSONEnv, applicationCredentialsEnv string)
- func (p *GoogleSTTProvider) StartSpeakerStream(ctx context.Context, opts speaker.Options, format speaker.AudioFormat) (speaker.SpeakerStream, error)
- func (p *GoogleSTTProvider) Transcribe(ctx context.Context, audio []byte, opts TranscribeOpts) (*Result, error)
- type HuggingFaceProvider
- type InstallStatus
- type LocalProvider
- func (*LocalProvider) Capabilities() []speechkit.Capability
- func (p *LocalProvider) Health(ctx context.Context) error
- func (p *LocalProvider) IsReady() bool
- func (p *LocalProvider) Name() string
- func (p *LocalProvider) RuntimeDone() <-chan struct{}
- func (p *LocalProvider) RuntimeError() error
- func (p *LocalProvider) StartServer(ctx context.Context) error
- func (p *LocalProvider) StopServer()
- func (p *LocalProvider) Transcribe(ctx context.Context, audioData []byte, opts TranscribeOpts) (*Result, error)
- func (p *LocalProvider) VerifyInstallation() InstallStatus
- type OpenAICompatibleProvider
- func NewGroqSTTProvider(apiKey string) *OpenAICompatibleProvider
- func NewOllamaSTTProvider(baseURL, model string) *OpenAICompatibleProvider
- func NewOpenAICompatibleProvider(name, baseURL, apiKey, model string) *OpenAICompatibleProvider
- func NewOpenAISTTProvider(apiKey string) *OpenAICompatibleProvider
- func NewVPSProvider(baseURL, apiKey string) *OpenAICompatibleProvider
- func NewVPSProviderWithModel(baseURL, apiKey, model string) *OpenAICompatibleProvider
- func (*OpenAICompatibleProvider) Capabilities() []speechkit.Capability
- func (p *OpenAICompatibleProvider) Health(ctx context.Context) error
- func (p *OpenAICompatibleProvider) Name() string
- func (p *OpenAICompatibleProvider) Transcribe(ctx context.Context, audio []byte, opts TranscribeOpts) (*Result, error)
- type OpenRouterSTTProvider
- type ResolvedTranscribeOptions
- type Result
- type STTProvider
- type TranscribeOpts
- type TranscriberOption
- type VPSProvider
- type WordConfidence
Constants ¶
const ( FluxEventStartOfTurn = "StartOfTurn" FluxEventUpdate = "Update" FluxEventEagerEndOfTurn = "EagerEndOfTurn" FluxEventTurnResumed = "TurnResumed" FluxEventEndOfTurn = "EndOfTurn" )
Flux turn lifecycle events. A turn opens with StartOfTurn, grows through Update events, and closes with EndOfTurn. EagerEndOfTurn is a speculative signal — the model believes the speaker is done and a consumer may start generating a response — which TurnResumed retracts when the speaker continues.
const ( FluxEOTThresholdMin = 0.5 FluxEOTThresholdMax = 0.9 FluxEagerEOTThresholdMin = 0.3 FluxEagerEOTThresholdMax = 0.9 FluxEOTTimeoutMinMs = 500 FluxEOTTimeoutMaxMs = 60000 )
Flux tuning ranges, per the Deepgram Flux API reference.
const ( DeepgramFluxModelEN = "flux-general-en" DeepgramFluxModelMulti = "flux-general-multi" )
Deepgram Flux model identifiers.
const DefaultAssemblyAITurnCleanupPrompt = "" /* 164-byte string literal not displayed */
DefaultAssemblyAITurnCleanupPrompt asks the gateway to tidy a single turn without summarizing. {{turn}} is substituted by AssemblyAI.
const FluxAudioChunk = 80 * time.Millisecond
FluxAudioChunk is the chunk duration Deepgram recommends for Flux input.
const LanguageMulti = "multi"
LanguageMulti is the value SpeechKit carries when no language is pinned.
SpeechKit does not narrow speech to one language: a pinned language breaks switching language mid-conversation and speaking different languages with different people in one session, and it is a silent data-loss bug — the same English audio returns a zero-length transcript when pinned to German, with HTTP 200 and no error.
It is deliberately NOT forwarded verbatim. Each provider expresses multilanguage in its own dialect: Deepgram takes the literal "multi", AssemblyAI sets language_detection, and the OpenAI-compatible, local and OpenRouter adapters express it by omitting the field so the model auto-detects. Sending "multi" to any of the latter is an invalid value.
const MinWhisperModelBytes = 50_000_000
MinWhisperModelBytes is the minimum file size we expect for a valid ggml model. ggml-base.bin is ~150 MB; anything under 50 MB is clearly corrupt/truncated.
Variables ¶
This section is empty.
Functions ¶
func AsTranscriber ¶ added in v0.61.28
func AsTranscriber(p STTProvider, opts ...TranscriberOption) speechkit.Transcriber
AsTranscriber adapts an STTProvider to the kernel's speechkit.Transcriber interface, so hosts can hand any provider straight to dictation.NewRuntime or a TranscriptionWorker without hand-writing the mechanical Result-to-Transcript adapter. The per-call language overrides the base option language when non-empty; when both are empty the request carries no language at all — the adapter never invents a default, because language selection (including multilanguage) is an explicit caller decision.
The device app keeps its own richer internal adapter (vocabulary bias, customization, routing); this bridge covers the plain provider-to-kernel path for library consumers.
func FindWhisperBinary ¶
FindWhisperBinary exposes the local whisper runtime lookup for callers that need to reflect runtime readiness without starting the subprocess.
func IsMultilanguage ¶ added in v0.53.0
IsMultilanguage reports whether language asks for multilanguage rather than a specific locale. Empty, "auto" and "multi" all mean the same thing: do not pin. The settings UI offers "auto" and "multi" as separate labels, so both have to resolve here or the literal token reaches providers that reject it.
func ParseDeepgramKeyterms ¶
func SetSecretResolver ¶
SetSecretResolver overrides how this package resolves named secrets (see resolveSecret). A nil resolver is ignored. Call once at startup, before constructing or using providers; the resolver is read when a provider opens a credentialed connection.
func SetSubprocessPriorityLowered ¶ added in v0.51.2
func SetSubprocessPriorityLowered(bool)
SetSubprocessPriorityLowered is a no-op outside Windows; subprocess priority classes are a Windows scheduling concept.
func ToTranscript ¶ added in v0.61.28
func ToTranscript(r *Result, durationSecs float64) speechkit.Transcript
ToTranscript maps a provider Result to a speechkit.Transcript. The mapping is mechanical: text, language, provider, model, confidence, per-word confidences, and speaker diarization pass through 1:1. Duration comes from the Result when the provider reported one; otherwise durationSecs (the caller-measured audio length) fills in. A nil Result yields a zero Transcript.
func ValidateModelPath ¶
ValidateModelPath verifies that path points at a whisper.cpp ggml model file with a safe filename. It rejects path traversal, non-absolute paths, and filenames that don't match the ggml-*.bin pattern.
Types ¶
type AssemblyAIProvider ¶
type AssemblyAIProvider struct {
APIKey string
Models []string
StreamingModel string
BaseURL string
StreamingBaseURL string
// SyncBaseURL points at the synchronous transcription endpoint
// (https://sync.assemblyai.com; regional variants sync.us / sync.eu
// exist). The Sync API returns a finished Universal-3.5 Pro transcript
// in one request/response (~134 ms p50) for clips up to 120 s / 40 MB —
// the low-latency dictation path. Empty uses the global endpoint.
SyncBaseURL string
// SyncModel is the X-AAI-Model routing header value for sync requests.
// Empty uses universal-3-5-pro.
SyncModel string
// DisableSync forces every transcription through the classic async
// upload+poll flow, even for clips the Sync API could serve.
DisableSync bool
// StreamingLLM, when set, attaches AssemblyAI LLM Gateway to Universal-3.5
// Pro realtime turns. The formatted transcript still arrives as Turn;
// LLMGatewayResponse may rewrite the final text for live cleanup.
StreamingLLM *AssemblyAIStreamingLLM
Validation netsec.ValidationOptions
PollInterval time.Duration
PollTimeout time.Duration
// contains filtered or unexported fields
}
func NewAssemblyAIProvider ¶
func NewAssemblyAIProvider(apiKey, models string) *AssemblyAIProvider
func (*AssemblyAIProvider) Capabilities ¶
func (*AssemblyAIProvider) Capabilities() []speechkit.Capability
AssemblyAI additionally attributes/identifies speakers against caller-supplied names or roles.
func (*AssemblyAIProvider) EnableStreamingLLM ¶ added in v0.61.12
func (p *AssemblyAIProvider) EnableStreamingLLM(model, prompt string, maxTokens int)
EnableStreamingLLM attaches LLM Gateway cleanup to realtime dictation.
func (*AssemblyAIProvider) Name ¶
func (p *AssemblyAIProvider) Name() string
func (*AssemblyAIProvider) StartDictationStream ¶ added in v0.50.0
func (p *AssemblyAIProvider) StartDictationStream(ctx context.Context, opts speechkit.DictationStreamOptions, format speaker.AudioFormat) (speechkit.DictationStream, error)
StartDictationStream opens a Universal-3.5 Pro realtime session for live dictation partials. DictationStreamOptions.PromptHint rides as agent_context — the "minimal situational info" (domain, audience, locale hints) the model conditions on from the first frame; finalized user turns are carried forward by the provider automatically. Finalize sends Terminate: the provider flushes the trailing turn, emits Termination, and closes the socket (Receive then returns io.EOF), which matches SpeechKit's one-provider-stream-per-segment model.
func (*AssemblyAIProvider) StartSpeakerStream ¶
func (p *AssemblyAIProvider) StartSpeakerStream(ctx context.Context, opts speaker.Options, format speaker.AudioFormat) (speaker.SpeakerStream, error)
func (*AssemblyAIProvider) Transcribe ¶
func (p *AssemblyAIProvider) Transcribe(ctx context.Context, audio []byte, opts TranscribeOpts) (*Result, error)
func (*AssemblyAIProvider) Warm ¶ added in v0.50.0
func (p *AssemblyAIProvider) Warm(ctx context.Context) error
Warm pre-establishes the HTTPS connection to the Sync API (DNS, TCP, TLS) so the subsequent /transcribe request skips connection setup. Hosts should call it when recording starts; the endpoint is unauthenticated and safe to call repeatedly, and idle connections are evicted after seconds to minutes, so warm close to the transcription rather than at startup.
type AssemblyAIStreamingLLM ¶ added in v0.61.12
AssemblyAIStreamingLLM is the LLM Gateway payload attached to a realtime dictation WebSocket. Model IDs are LLM Gateway catalog names, not STT names.
type CapabilityReporter ¶
type CapabilityReporter interface {
Capabilities() []speechkit.Capability
}
CapabilityReporter is an optional interface a provider can implement to self-describe its capabilities. Routing and catalogs can type-assert it to query capabilities directly instead of string-matching profile IDs.
It is intentionally NOT part of STTProvider, so existing providers, server clients, and test doubles continue to satisfy the core interface without change; only the production providers below opt in. Capabilities are reported using the public speechkit.Capability vocabulary so the adapters carry no internal/ dependency.
type DeepgramOptions ¶
type DeepgramOptions struct {
Configured bool
SmartFormat bool
Dictation bool
FillerWords bool
Numerals bool
DetectLanguage bool
LanguageOverride string
UseVocabularyKeyterms bool
Keyterms []string
EndpointingMs int
}
DeepgramOptions holds provider-specific Deepgram STT controls. These map to Deepgram Listen query parameters while keeping SpeechKit's public STT router interface provider-neutral.
type DeepgramProvider ¶
type DeepgramProvider struct {
APIKey string
Model string
DiarizationModel string
BaseURL string
Validation netsec.ValidationOptions
SmartFormat bool
Dictation bool
FillerWords bool
Numerals bool
DetectLanguage bool
LanguageOverride string
UseVocabularyKeyterms bool
Keyterms []string
EndpointingMs int
// contains filtered or unexported fields
}
func NewDeepgramProvider ¶
func NewDeepgramProvider(apiKey, model string) *DeepgramProvider
func (*DeepgramProvider) ApplyOptions ¶
func (p *DeepgramProvider) ApplyOptions(opts DeepgramOptions)
func (*DeepgramProvider) Capabilities ¶
func (*DeepgramProvider) Capabilities() []speechkit.Capability
Deepgram and Google add batch speaker diarization (live-verified in the speaker layer).
func (*DeepgramProvider) Name ¶
func (p *DeepgramProvider) Name() string
func (*DeepgramProvider) StartDictationStream ¶ added in v0.48.0
func (p *DeepgramProvider) StartDictationStream(ctx context.Context, opts speechkit.DictationStreamOptions, format speaker.AudioFormat) (speechkit.DictationStream, error)
func (*DeepgramProvider) StartFluxTurnStream ¶ added in v0.54.10
func (p *DeepgramProvider) StartFluxTurnStream(ctx context.Context, opts FluxStreamOptions, format speaker.AudioFormat) (*FluxTurnStream, error)
StartFluxTurnStream opens a Deepgram Flux /v2/listen stream. The format must be raw PCM; Deepgram recommends 16 kHz mono and FluxAudioChunk-sized writes.
func (*DeepgramProvider) StartSpeakerStream ¶
func (p *DeepgramProvider) StartSpeakerStream(ctx context.Context, opts speaker.Options, format speaker.AudioFormat) (speaker.SpeakerStream, error)
func (*DeepgramProvider) Transcribe ¶
func (p *DeepgramProvider) Transcribe(ctx context.Context, audio []byte, opts TranscribeOpts) (*Result, error)
type FluxStreamOptions ¶ added in v0.54.10
type FluxStreamOptions struct {
// Model selects flux-general-en or flux-general-multi. Empty uses the
// multilingual model, which is the point of Flux for SpeechKit: it detects
// and switches languages within a single conversation.
Model string
// LanguageHints biases recognition toward the given BCP-47 languages. Only
// flux-general-multi accepts hints; they narrow the model, they do not pin
// it, and every turn still reports what it actually heard.
LanguageHints []string
// Keyterms boost domain vocabulary (product names and other terms the model
// has not seen).
Keyterms []string
// EOTThreshold, EagerEOTThreshold, and EOTTimeoutMs tune turn detection.
// Zero keeps Deepgram's defaults; out-of-range values are clamped.
EOTThreshold float64
EagerEOTThreshold float64
EOTTimeoutMs int
}
FluxStreamOptions configures a Flux turn stream. The zero value is valid and selects the multilingual model with Deepgram's default turn detection.
type FluxTurn ¶ added in v0.54.10
type FluxTurn struct {
// Event is one of the Flux lifecycle events above.
Event string `json:"event"`
// TurnIndex counts turns within the connection.
TurnIndex int `json:"turnIndex"`
// Transcript is the full turn transcript so far, not a delta.
Transcript string `json:"transcript"`
Words []FluxWord `json:"words,omitempty"`
// Languages are the languages actually detected in this turn; empty when
// the turn holds no speech yet.
Languages []string `json:"languages,omitempty"`
// EndOfTurnConfidence is the model's confidence that the speaker is done.
EndOfTurnConfidence float64 `json:"endOfTurnConfidence"`
// AudioWindowStartMs/EndMs bound the audio this turn covers.
AudioWindowStartMs int64 `json:"audioWindowStartMs"`
AudioWindowEndMs int64 `json:"audioWindowEndMs"`
// SequenceID is Deepgram's per-connection event counter.
SequenceID int64 `json:"sequenceId"`
// RequestID identifies the connection in Deepgram's logs.
RequestID string `json:"requestId"`
// LatencyMs is the time from stream open to this event.
LatencyMs int64 `json:"latencyMs"`
}
FluxTurn is one decoded TurnInfo event.
func (FluxTurn) IsFinal ¶ added in v0.54.10
IsFinal reports whether the turn is closed and the transcript will not grow.
func (FluxTurn) IsSpeculative ¶ added in v0.54.10
IsSpeculative reports whether the event is the eager end-of-turn signal, which TurnResumed can retract. A consumer may start work on it, but must be able to cancel that work.
type FluxTurnStream ¶ added in v0.54.10
type FluxTurnStream struct {
// contains filtered or unexported fields
}
FluxTurnStream is a live Flux connection. Callers push PCM with SendPCM and read turn events with Receive until io.EOF.
func (*FluxTurnStream) Close ¶ added in v0.54.10
func (s *FluxTurnStream) Close() error
Close shuts the WebSocket down. It is safe to call more than once.
func (*FluxTurnStream) CloseStream ¶ added in v0.54.10
func (s *FluxTurnStream) CloseStream(ctx context.Context) error
CloseStream tells Deepgram no further audio is coming, so it can flush the open turn instead of waiting for the end-of-turn timeout.
func (*FluxTurnStream) Model ¶ added in v0.54.10
func (s *FluxTurnStream) Model() string
Model reports the Flux model this stream negotiated.
type FluxWord ¶ added in v0.54.10
type FluxWord struct {
Text string `json:"text"`
Confidence float64 `json:"confidence"`
StartMs int64 `json:"startMs"`
EndMs int64 `json:"endMs"`
}
FluxWord is a single recognized word. Flux reports no speaker label and no separately punctuated form — the turn transcript carries the punctuation.
type GoogleSTTProvider ¶
type GoogleSTTProvider struct {
APIKey string
Model string // "latest_long", "latest_short", or another Google STT v1 model tag
STTCredentialsJSONEnv string
ApplicationCredentialsEnv string
BaseURL string // Override for testing; defaults to googleSTTBaseURL
Validation netsec.ValidationOptions
// contains filtered or unexported fields
}
GoogleSTTProvider implements STTProvider for Google Cloud Speech-to-Text v1 REST API.
BaseURL is user-configurable (for testing or regional endpoints). It is validated against Validation on every request. Default Validation is strict (public https only).
func NewGoogleSTTProvider ¶
func NewGoogleSTTProvider(apiKey, model string) *GoogleSTTProvider
NewGoogleSTTProvider creates a provider for Google Cloud Speech-to-Text. Model defaults to "latest_long" if empty.
func (*GoogleSTTProvider) Capabilities ¶
func (*GoogleSTTProvider) Capabilities() []speechkit.Capability
func (*GoogleSTTProvider) Health ¶
func (p *GoogleSTTProvider) Health(ctx context.Context) error
Health checks if the Google Speech API is reachable.
func (*GoogleSTTProvider) Name ¶
func (p *GoogleSTTProvider) Name() string
Name returns the provider identifier.
func (*GoogleSTTProvider) SetStreamingCredentialEnvs ¶
func (p *GoogleSTTProvider) SetStreamingCredentialEnvs(credentialsJSONEnv, applicationCredentialsEnv string)
func (*GoogleSTTProvider) StartSpeakerStream ¶
func (p *GoogleSTTProvider) StartSpeakerStream(ctx context.Context, opts speaker.Options, format speaker.AudioFormat) (speaker.SpeakerStream, error)
StartSpeakerStream opens a Google Cloud Speech-to-Text v2 StreamingRecognize session.
IMPORTANT: Google STT v2 does NOT support speaker diarization in streaming mode — diarization is available only in BatchRecognize/Recognize (see the Chirp-3 docs). This adapter therefore provides realtime TRANSCRIPTION only: frames carry Text without speaker labels (no Segment/Speakers). Streaming speaker diarization in the Voice Agent comes from Deepgram/AssemblyAI.
func (*GoogleSTTProvider) Transcribe ¶
func (p *GoogleSTTProvider) Transcribe(ctx context.Context, audio []byte, opts TranscribeOpts) (*Result, error)
Transcribe sends audio to Google Cloud Speech-to-Text v1 REST API.
type HuggingFaceProvider ¶
type HuggingFaceProvider struct {
Model string
Token string
BaseURL string // Override for testing; defaults to hfBaseURL
Validation netsec.ValidationOptions
// contains filtered or unexported fields
}
HuggingFaceProvider implements STTProvider for Tier 3: HuggingFace Inference API.
BaseURL is user-configurable. It is validated against Validation on every request. Default Validation is strict (public https only).
func NewHuggingFaceProvider ¶
func NewHuggingFaceProvider(model, token string) *HuggingFaceProvider
func (*HuggingFaceProvider) Capabilities ¶
func (*HuggingFaceProvider) Capabilities() []speechkit.Capability
func (*HuggingFaceProvider) Health ¶
func (p *HuggingFaceProvider) Health(ctx context.Context) error
func (*HuggingFaceProvider) Name ¶
func (p *HuggingFaceProvider) Name() string
func (*HuggingFaceProvider) Transcribe ¶
func (p *HuggingFaceProvider) Transcribe(ctx context.Context, audio []byte, opts TranscribeOpts) (*Result, error)
type InstallStatus ¶
type InstallStatus struct {
BinaryFound bool `json:"binaryFound"`
BinaryPath string `json:"binaryPath"`
ModelFound bool `json:"modelFound"`
ModelPath string `json:"modelPath"`
ModelBytes int64 `json:"modelBytes"`
ServerReady bool `json:"serverReady"`
Problems []string `json:"problems,omitempty"`
}
InstallStatus describes what's present and what's missing for local STT.
type LocalProvider ¶
type LocalProvider struct {
BaseURL string // e.g. "http://127.0.0.1:8080"
Port int
ModelPath string
GPU string
Validation netsec.ValidationOptions
// contains filtered or unexported fields
}
LocalProvider implements STTProvider for Tier 1: localhost whisper.cpp server.
func NewLocalProvider ¶
func NewLocalProvider(port int, modelPath, gpu string) *LocalProvider
func (*LocalProvider) Capabilities ¶
func (*LocalProvider) Capabilities() []speechkit.Capability
func (*LocalProvider) IsReady ¶
func (p *LocalProvider) IsReady() bool
IsReady returns true if the whisper-server subprocess is running and responding.
func (*LocalProvider) Name ¶
func (p *LocalProvider) Name() string
func (*LocalProvider) RuntimeDone ¶ added in v0.54.0
func (p *LocalProvider) RuntimeDone() <-chan struct{}
RuntimeDone closes whenever the owned whisper-server subprocess exits. RuntimeError then reports an unexpected exit and stays nil for an explicit StopServer call or process-context cancellation.
func (*LocalProvider) RuntimeError ¶ added in v0.54.0
func (p *LocalProvider) RuntimeError() error
func (*LocalProvider) StartServer ¶
func (p *LocalProvider) StartServer(ctx context.Context) error
StartServer starts the whisper.cpp server subprocess. Blocks until ready or context cancelled.
func (*LocalProvider) StopServer ¶
func (p *LocalProvider) StopServer()
StopServer terminates the whisper-server subprocess.
func (*LocalProvider) Transcribe ¶
func (p *LocalProvider) Transcribe(ctx context.Context, audioData []byte, opts TranscribeOpts) (*Result, error)
func (*LocalProvider) VerifyInstallation ¶
func (p *LocalProvider) VerifyInstallation() InstallStatus
VerifyInstallation checks binary and model availability without starting the server.
type OpenAICompatibleProvider ¶
type OpenAICompatibleProvider struct {
BaseURL string
APIKey string
Model string
Validation netsec.ValidationOptions
// contains filtered or unexported fields
}
OpenAICompatibleProvider implements STTProvider for any endpoint speaking the OpenAI /v1/audio/transcriptions API (OpenAI, Groq, VPS whisper-server, etc.).
BaseURL is user-supplied configuration. It is validated against Validation on every request (Transcribe, Health). The default Validation is strict: only public https:// endpoints are accepted. Self-hosted VPS and local whisper-server require relaxing Validation — see NewVPSProvider.
func NewGroqSTTProvider ¶
func NewGroqSTTProvider(apiKey string) *OpenAICompatibleProvider
NewGroqSTTProvider creates a provider for the Groq Whisper API.
func NewOllamaSTTProvider ¶
func NewOllamaSTTProvider(baseURL, model string) *OpenAICompatibleProvider
NewOllamaSTTProvider creates a provider for Ollama-compatible local transcription endpoints. Ollama runs on loopback by default and can be pointed at a user-managed self-hosted URL.
func NewOpenAICompatibleProvider ¶
func NewOpenAICompatibleProvider(name, baseURL, apiKey, model string) *OpenAICompatibleProvider
NewOpenAICompatibleProvider creates a provider for any OpenAI-compatible STT endpoint. Default Validation is strict (public https only). Callers with a non-public endpoint (loopback, RFC1918) must set Validation explicitly.
func NewOpenAISTTProvider ¶
func NewOpenAISTTProvider(apiKey string) *OpenAICompatibleProvider
NewOpenAISTTProvider creates a provider for the OpenAI Whisper API.
func NewVPSProvider ¶
func NewVPSProvider(baseURL, apiKey string) *OpenAICompatibleProvider
NewVPSProvider creates a provider for a self-hosted whisper-server. Allows loopback, private IP ranges and plain http:// because self-hosted deployments frequently run inside a VPN, on a home LAN, or on localhost.
func NewVPSProviderWithModel ¶
func NewVPSProviderWithModel(baseURL, apiKey, model string) *OpenAICompatibleProvider
func (*OpenAICompatibleProvider) Capabilities ¶
func (*OpenAICompatibleProvider) Capabilities() []speechkit.Capability
func (*OpenAICompatibleProvider) Health ¶
func (p *OpenAICompatibleProvider) Health(ctx context.Context) error
Health checks provider reachability. Tries GET /health first (whisper-server), then falls back to GET /v1/models (OpenAI, Groq).
func (*OpenAICompatibleProvider) Name ¶
func (p *OpenAICompatibleProvider) Name() string
Name returns the provider identifier.
func (*OpenAICompatibleProvider) Transcribe ¶
func (p *OpenAICompatibleProvider) Transcribe(ctx context.Context, audio []byte, opts TranscribeOpts) (*Result, error)
Transcribe sends audio to the OpenAI-compatible /v1/audio/transcriptions endpoint.
type OpenRouterSTTProvider ¶
type OpenRouterSTTProvider struct {
BaseURL string
APIKey string
Model string
Validation netsec.ValidationOptions
// contains filtered or unexported fields
}
OpenRouterSTTProvider implements OpenRouter's JSON speech-to-text endpoint. OpenRouter is a cloud gateway, not a direct model provider, and its STT API accepts base64 audio rather than OpenAI's multipart Whisper shape.
func NewOpenRouterSTTProvider ¶
func NewOpenRouterSTTProvider(apiKey, model string) *OpenRouterSTTProvider
func (*OpenRouterSTTProvider) Capabilities ¶
func (*OpenRouterSTTProvider) Capabilities() []speechkit.Capability
func (*OpenRouterSTTProvider) Health ¶
func (p *OpenRouterSTTProvider) Health(ctx context.Context) error
func (*OpenRouterSTTProvider) Name ¶
func (p *OpenRouterSTTProvider) Name() string
func (*OpenRouterSTTProvider) Transcribe ¶
func (p *OpenRouterSTTProvider) Transcribe(ctx context.Context, audio []byte, opts TranscribeOpts) (*Result, error)
type ResolvedTranscribeOptions ¶
type ResolvedTranscribeOptions struct {
Language string
Model string
Prompt string
ContextPrompt string
LanguageHints []string
Keyterms []string
Speaker speaker.Options
DetectLanguage bool
Punctuation bool
SmartFormat bool
Dictation bool
FillerWords bool
Numerals bool
UseVocabularyKeyterms bool
Timestamps bool
EndpointingMs int
PrivacyRedaction bool
VoiceFocus bool
MedicalDomain bool
Effective provideropts.EffectiveOptions
}
func ResolveTranscribeOptions ¶
func ResolveTranscribeOptions(provider, profileID string, opts TranscribeOpts, providerDefaults, providerOverrides provideropts.Values) ResolvedTranscribeOptions
func (ResolvedTranscribeOptions) APILanguage ¶
func (r ResolvedTranscribeOptions) APILanguage() string
type Result ¶
type Result struct {
Text string
Language string
Duration time.Duration
Provider string
Model string
Confidence float64 // If available from the provider
// Words carries per-word acoustic confidence when the provider exposes it.
// nil for providers without word-level confidence. Offsets are NOT tracked
// because downstream vocabulary/punctuation rewriting invalidates them;
// consumers match on the word text instead.
Words []WordConfidence
Speakers *speaker.DiarizationResult
}
Result holds the output of a transcription.
type STTProvider ¶
type STTProvider interface {
// Transcribe sends audio data to the STT backend and returns the transcription.
Transcribe(ctx context.Context, audio []byte, opts TranscribeOpts) (*Result, error)
// Name returns the provider identifier (e.g. "local", "vps", "huggingface").
Name() string
// Health checks if the provider is reachable and ready.
Health(ctx context.Context) error
}
STTProvider defines the interface for all speech-to-text backends.
type TranscribeOpts ¶
type TranscribeOpts struct {
Language string // "de", "en", "auto"; request override only
Model string // Optional: model override
Prompt string // Optional: provider-specific hint prompt for better recognition
Keyterms []string // Optional: provider-native vocabulary bias terms
// ConversationContext carries the preceding dialogue turns (oldest
// first, no speaker labels) for providers whose models condition on
// conversational context — e.g. AssemblyAI Universal-3.5 Pro sync
// accepts up to 100 turns / 4096 chars via conversation_context.
// Distinct from Prompt (which describes the domain/scenario) and
// Keyterms (explicit vocabulary). Providers without native support
// ignore it.
ConversationContext []string
// ProviderProfileID prioritizes a provider for this request. Accepts a
// full provider-profile ID (e.g. "stt.deepgram.nova-3") or a bare
// provider ID (e.g. "deepgram"); routers move matching providers to the
// front of their candidate list while keeping the remaining providers as
// fallbacks. An unknown or unconfigured value changes nothing — a
// request never hard-fails on an unsatisfiable preference. Mirrors
// speechkit.DictationStreamOptions.ProviderProfileID for the batch path.
ProviderProfileID string
Speaker speaker.Options // Optional speaker diarization / attribution request
Options provideropts.Values // Optional normalized global/default voice options
ProviderOptions provideropts.Values // Optional normalized overrides for the selected provider
ProviderOptionsByProvider map[string]provideropts.Values // Optional provider-keyed overrides used by routers
}
TranscribeOpts configures a single transcription request.
func (TranscribeOpts) ForProvider ¶
func (o TranscribeOpts) ForProvider(provider string) TranscribeOpts
type TranscriberOption ¶ added in v0.61.28
type TranscriberOption func(*transcriberOptions)
TranscriberOption configures the adapter returned by AsTranscriber.
func WithTranscribeOpts ¶ added in v0.61.28
func WithTranscribeOpts(base TranscribeOpts) TranscriberOption
WithTranscribeOpts sets the base TranscribeOpts applied to every request the adapter makes (prompt, keyterms, provider options, and so on). The Language field of the base is used only when the per-call language passed to Transcribe is empty; a non-empty per-call language always wins.
type VPSProvider ¶
type VPSProvider = OpenAICompatibleProvider
VPSProvider is an alias for backward compatibility. Use OpenAICompatibleProvider directly for new code.
type WordConfidence ¶
WordConfidence is a single recognized word with the provider's per-word acoustic confidence in [0,1]. It is populated only by providers that expose word-level confidence (Deepgram, AssemblyAI); it stays nil for providers that do not (Google v1, OpenAI/Groq/HuggingFace Whisper, local whisper.cpp). Confidence here is acoustic (how sure the model is it heard this word), not semantic — a low value flags a likely mis-recognition or dropped word.
Source Files
¶
- assemblyai.go
- assemblyai_streaming.go
- assemblyai_sync.go
- capabilities.go
- deepgram.go
- deepgram_flux_streaming.go
- deepgram_streaming.go
- google.go
- google_streaming.go
- huggingface.go
- local.go
- local_search_unix.go
- openai_compatible.go
- openrouter.go
- options.go
- process_other.go
- provider.go
- secrets.go
- transcriber.go
- vps.go
- wav.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sttcontract provides a reusable conformance suite that every stt.STTProvider implementation is expected to satisfy.
|
Package sttcontract provides a reusable conformance suite that every stt.STTProvider implementation is expected to satisfy. |