router

package
v0.40.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package router implements the STT routing layer. It picks the right provider (local, cloud, or direct) for a transcription request based on the configured Strategy (Dynamic, LocalOnly, CloudOnly) and current connectivity / readiness.

The router is platform-neutral and is consumed by both the Device- Target (Wails client) and the Server-Target. TTS has a parallel routing layer in package tts; this package is STT-only.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Router

type Router struct {
	Strategy             Strategy
	PreferLocalUnderSecs float64
	ParallelCloud        bool
	ReplaceOnBetter      bool
	// ConnectivityProbe is the TCP address used to test internet connectivity.
	// Defaults to "1.1.1.1:443" when empty.
	ConnectivityProbe string
	// contains filtered or unexported fields
}

Router selects the best STTProvider based on audio length, availability, and config.

func (*Router) AddCloud

func (r *Router) AddCloud(p stt.STTProvider)

AddCloud appends a cloud provider to the ordered list (thread-safe).

func (*Router) AvailableProviders

func (r *Router) AvailableProviders() []string

AvailableProviders returns the names of configured providers.

func (*Router) Cloud

func (r *Router) Cloud(name string) stt.STTProvider

Cloud returns a cloud provider by name, or nil if not found.

func (*Router) HuggingFace

func (r *Router) HuggingFace() stt.STTProvider

HuggingFace returns the HuggingFace cloud provider (backward-compatible convenience).

func (*Router) Local

func (r *Router) Local() stt.STTProvider

Local returns the current local provider.

func (*Router) PreferCloud added in v0.14.6

func (r *Router) PreferCloud(name string, p stt.STTProvider)

PreferCloud sets/replaces a cloud provider and moves it to the front so it becomes the next cloud provider used by routing, while keeping remaining providers as fallbacks.

func (*Router) Route

func (r *Router) Route(ctx context.Context, audio []byte, audioDurationSecs float64, opts stt.TranscribeOpts) (*stt.Result, error)

Route selects the appropriate provider(s) and returns the transcription result.

func (*Router) SetCloud

func (r *Router) SetCloud(name string, p stt.STTProvider)

SetCloud replaces a cloud provider by name, or appends if not found. Pass nil to remove the provider with that name.

func (*Router) SetCloudProviders added in v0.21.1

func (r *Router) SetCloudProviders(providers []stt.STTProvider)

SetCloudProviders replaces the ordered cloud provider list.

func (*Router) SetHuggingFace

func (r *Router) SetHuggingFace(p stt.STTProvider)

SetHuggingFace sets/replaces the HuggingFace cloud provider (backward-compatible convenience).

func (*Router) SetLocal

func (r *Router) SetLocal(p stt.STTProvider)

SetLocal sets the local provider (thread-safe).

func (*Router) SetVPS

func (r *Router) SetVPS(p stt.STTProvider)

SetVPS sets/replaces the VPS cloud provider (backward-compatible convenience).

func (*Router) VPS

func (r *Router) VPS() stt.STTProvider

VPS returns the VPS cloud provider (backward-compatible convenience).

type Strategy

type Strategy string

Strategy defines the routing strategy.

const (
	StrategyDynamic   Strategy = "dynamic"
	StrategyLocalOnly Strategy = "local-only"
	StrategyCloudOnly Strategy = "cloud-only"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL