stt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlignedTranscript

type AlignedTranscript string
const (
	AlignedTranscriptNone  AlignedTranscript = ""
	AlignedTranscriptWord  AlignedTranscript = "word"
	AlignedTranscriptChunk AlignedTranscript = "chunk"
)

type AvailabilityChangedEvent

type AvailabilityChangedEvent struct {
	STT       STT
	Available bool
}

AvailabilityChangedEvent reports a provider entering or leaving the fallback rotation.

type Base

type Base struct {
	// contains filtered or unexported fields
}

Base implements provider metadata and typed events for STT implementations.

func NewBase

func NewBase(label, provider, model string, capabilities Capabilities) *Base

func (*Base) Capabilities

func (b *Base) Capabilities() Capabilities

func (*Base) EmitError

func (b *Base) EmitError(event ErrorEvent)

func (*Base) EmitMetrics

func (b *Base) EmitMetrics(metric metrics.STT)

func (*Base) Label

func (b *Base) Label() string

func (*Base) Model

func (b *Base) Model() string

func (*Base) OnError

func (b *Base) OnError(fn func(ErrorEvent)) func()

func (*Base) OnMetrics

func (b *Base) OnMetrics(fn func(metrics.STT)) func()

func (*Base) Provider

func (b *Base) Provider() string

func (*Base) SetModel

func (b *Base) SetModel(model string)

func (*Base) UpdateCapabilities

func (b *Base) UpdateCapabilities(update func(*Capabilities))

type BaseStream

type BaseStream struct {
	// contains filtered or unexported fields
}

BaseStream supplies bounded input/output, lifecycle, and cancellation. A provider owns the run goroutine and consumes Inputs until io.EOF.

func NewBaseStream

func NewBaseStream(parent context.Context, capacity int) *BaseStream

func (*BaseStream) Close

func (s *BaseStream) Close() error

func (*BaseStream) Context

func (s *BaseStream) Context() context.Context

func (*BaseStream) Emit

func (s *BaseStream) Emit(ctx context.Context, event SpeechEvent) error

func (*BaseStream) EndInput

func (s *BaseStream) EndInput() error

func (*BaseStream) Finish

func (s *BaseStream) Finish(err error)

func (*BaseStream) Flush

func (s *BaseStream) Flush(ctx context.Context) error

func (*BaseStream) Inputs

func (s *BaseStream) Inputs() stream.Reader[StreamInput]

func (*BaseStream) Push

func (s *BaseStream) Push(ctx context.Context, frame agents.AudioFrame) error

func (*BaseStream) Recv

func (s *BaseStream) Recv(ctx context.Context) (SpeechEvent, error)

type Capabilities

type Capabilities struct {
	Streaming         bool
	InterimResults    bool
	AlignedTranscript AlignedTranscript
	Diarization       bool
	Keyterms          bool
	ChatContext       bool
}

type ErrorEvent

type ErrorEvent struct {
	Timestamp   time.Time
	Label       string
	Err         error
	Recoverable bool
}

type FallbackAdapter

type FallbackAdapter struct {
	// contains filtered or unexported fields
}

FallbackAdapter provides ordered STT failover, health recovery, automatic VAD wrapping for batch-only providers, and dynamic provider attribution.

func NewFallbackAdapter

func NewFallbackAdapter(options FallbackOptions) (*FallbackAdapter, error)

func (*FallbackAdapter) AttemptTimeout

func (a *FallbackAdapter) AttemptTimeout() time.Duration

func (*FallbackAdapter) Availability

func (a *FallbackAdapter) Availability() []bool

func (*FallbackAdapter) Capabilities

func (a *FallbackAdapter) Capabilities() Capabilities

func (*FallbackAdapter) Close

func (a *FallbackAdapter) Close(ctx context.Context) error

func (*FallbackAdapter) Instances

func (a *FallbackAdapter) Instances() []STT

Instances is a Python/TypeScript-friendly alias for STTs.

func (*FallbackAdapter) Label

func (a *FallbackAdapter) Label() string

func (*FallbackAdapter) MaxRetriesPerSTT

func (a *FallbackAdapter) MaxRetriesPerSTT() int

func (*FallbackAdapter) Model

func (a *FallbackAdapter) Model() string

func (*FallbackAdapter) OnAvailabilityChanged

func (a *FallbackAdapter) OnAvailabilityChanged(fn func(AvailabilityChangedEvent)) func()

func (*FallbackAdapter) OnError

func (a *FallbackAdapter) OnError(fn func(ErrorEvent)) func()

func (*FallbackAdapter) OnMetrics

func (a *FallbackAdapter) OnMetrics(fn func(metrics.STT)) func()

func (*FallbackAdapter) Provider

func (a *FallbackAdapter) Provider() string

func (*FallbackAdapter) Recognize

func (a *FallbackAdapter) Recognize(parent context.Context, frames []agents.AudioFrame, options RecognizeOptions) (SpeechEvent, error)

func (*FallbackAdapter) RetryInterval

func (a *FallbackAdapter) RetryInterval() time.Duration

func (*FallbackAdapter) STTs

func (a *FallbackAdapter) STTs() []STT

func (*FallbackAdapter) Status

func (a *FallbackAdapter) Status() []FallbackStatus

func (*FallbackAdapter) Stream

func (a *FallbackAdapter) Stream(parent context.Context, options StreamOptions) (SpeechStream, error)

type FallbackOptions

type FallbackOptions struct {
	STTs []STT
	// STTInstances is the agents-js-compatible spelling. Set only one of
	// STTs or STTInstances.
	STTInstances     []STT
	VAD              vad.VAD
	AttemptTimeout   time.Duration
	MaxRetriesPerSTT int
	// MaxRetryPerSTT is the agents-js-compatible spelling. Non-zero values
	// override MaxRetriesPerSTT.
	MaxRetryPerSTT int
	RetryInterval  time.Duration
	StreamCapacity int

	// KeepProvidersOpen leaves the original STT instances caller-owned. By
	// default Close shuts them down after all adapter work has stopped.
	KeepProvidersOpen bool
}

FallbackOptions configures ordered STT failover. A zero timeout, retry interval, or stream capacity selects the agents-js 1.7 defaults. A zero MaxRetriesPerSTT selects the default of one; use a negative value to disable child retries explicitly (mirroring APIConnectOptions).

type FallbackStatus

type FallbackStatus struct {
	Available  bool
	Recovering bool
}

FallbackStatus is an immutable status snapshot.

type RecognitionUsage

type RecognitionUsage struct {
	AudioDuration time.Duration
	InputTokens   int64
	OutputTokens  int64
}

type RecognizeOptions

type RecognizeOptions struct {
	ConnectOptions agents.APIConnectOptions
	Language       agents.LanguageCode
}

type STT

type STT interface {
	Label() string
	Provider() string
	Model() string
	Capabilities() Capabilities
	Recognize(context.Context, []agents.AudioFrame, RecognizeOptions) (SpeechEvent, error)
	Stream(context.Context, StreamOptions) (SpeechStream, error)
	Close(context.Context) error
	OnMetrics(func(metrics.STT)) func()
	OnError(func(ErrorEvent)) func()
}

type SessionKeytermUpdater

type SessionKeytermUpdater interface {
	UpdateSessionKeyterms(keyterms []string) error
}

SessionKeytermUpdater is implemented by recognizers that can update the framework-managed keyterm overlay without replacing caller-provided model options. AgentSession uses this optional interface only when Capabilities().Keyterms is true.

Implementations must copy keyterms before returning. An empty slice clears keyterms left by a previous session binding.

type SpeechData

type SpeechData struct {
	Language        agents.LanguageCode
	Text            string
	StartTime       time.Duration
	EndTime         time.Duration
	Confidence      float64
	Words           []agents.TimedString
	SpeakerID       string
	SourceLanguages []agents.LanguageCode
	SourceTexts     []string
	TargetLanguages []agents.LanguageCode
	TargetTexts     []string
	Metadata        map[string]any
}

type SpeechEvent

type SpeechEvent struct {
	Type             SpeechEventType
	Alternatives     []SpeechData
	RequestID        string
	RecognitionUsage *RecognitionUsage
}

func MeasureRecognize

func MeasureRecognize(
	ctx context.Context,
	base *Base,
	frames []agents.AudioFrame,
	request func(context.Context) (SpeechEvent, error),
) (SpeechEvent, error)

MeasureRecognize provides the common metrics behavior of the TS/Python base class while leaving the provider request implementation allocation-free.

type SpeechEventType

type SpeechEventType uint8
const (
	StartOfSpeech SpeechEventType = iota
	InterimTranscript
	FinalTranscript
	EndOfSpeech
	RecognitionUsageEvent
	PreflightTranscript
)

type SpeechStream

type SpeechStream interface {
	stream.Reader[SpeechEvent]
	Push(context.Context, agents.AudioFrame) error
	Flush(context.Context) error
	EndInput() error
	Close() error
}

type StreamAdapter

type StreamAdapter struct {
	// contains filtered or unexported fields
}

StreamAdapter turns a batch STT into a streaming STT by recognizing each utterance delimited by a VAD. The wrapped STT and VAD remain caller-owned. Child metrics and errors are forwarded without generating duplicate adapter metrics.

func NewStreamAdapter

func NewStreamAdapter(wrapped STT, detector vad.VAD, options ...StreamAdapterOptions) (*StreamAdapter, error)

NewStreamAdapter constructs a VAD-backed streaming adapter. At most one options value is accepted.

func (*StreamAdapter) Capabilities

func (a *StreamAdapter) Capabilities() Capabilities

func (*StreamAdapter) Close

func (a *StreamAdapter) Close(ctx context.Context) error

Close cancels active adapter streams, detaches forwarded listeners, and waits for their goroutines. It intentionally does not close the caller-owned wrapped STT or VAD.

func (*StreamAdapter) Label

func (a *StreamAdapter) Label() string

func (*StreamAdapter) Model

func (a *StreamAdapter) Model() string

func (*StreamAdapter) OnError

func (a *StreamAdapter) OnError(fn func(ErrorEvent)) func()

func (*StreamAdapter) OnMetrics

func (a *StreamAdapter) OnMetrics(fn func(metrics.STT)) func()

func (*StreamAdapter) Provider

func (a *StreamAdapter) Provider() string

func (*StreamAdapter) Recognize

func (a *StreamAdapter) Recognize(ctx context.Context, frames []agents.AudioFrame, options RecognizeOptions) (SpeechEvent, error)

func (*StreamAdapter) Stream

func (a *StreamAdapter) Stream(parent context.Context, options StreamOptions) (SpeechStream, error)

func (*StreamAdapter) WrappedSTT

func (a *StreamAdapter) WrappedSTT() STT

type StreamAdapterOptions

type StreamAdapterOptions struct {
	StreamCapacity int
}

StreamAdapterOptions controls the bounded queues used by StreamAdapter. Zero values select production defaults.

type StreamAdapterWrapper

type StreamAdapterWrapper struct {
	*BaseStream
	// contains filtered or unexported fields
}

StreamAdapterWrapper is the concrete SpeechStream returned by StreamAdapter. Wait is useful when deterministic shutdown is required.

func (*StreamAdapterWrapper) Close

func (s *StreamAdapterWrapper) Close() error

func (*StreamAdapterWrapper) Wait

type StreamInput

type StreamInput struct {
	Frame *agents.AudioFrame
	Flush bool
}

type StreamOptions

type StreamOptions struct {
	ConnectOptions agents.APIConnectOptions
	Language       agents.LanguageCode
}

Directories

Path Synopsis
Package stttest contains deterministic STT test doubles.
Package stttest contains deterministic STT test doubles.

Jump to

Keyboard shortcuts

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