stt

package
v0.0.99 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const STTErrorType = "stt_error"

Variables

This section is empty.

Functions

func Model added in v0.0.15

func Model(stt STT) string

func Prewarm added in v0.0.15

func Prewarm(stt STT)

func Provider added in v0.0.15

func Provider(stt STT) string

func SetStreamStartTime added in v0.0.15

func SetStreamStartTime(stream StreamTiming, startTime float64)

func SetStreamStartTimeOffset added in v0.0.15

func SetStreamStartTimeOffset(stream StreamTiming, offset float64)

Types

type AvailabilityChangedEvent added in v0.0.15

type AvailabilityChangedEvent struct {
	STT       STT
	Available bool
}

type AvailabilityChangedHandler added in v0.0.15

type AvailabilityChangedHandler func(AvailabilityChangedEvent)

type ErrorEmitter added in v0.0.15

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

func (*ErrorEmitter) EmitError added in v0.0.15

func (e *ErrorEmitter) EmitError(err *STTError)

func (*ErrorEmitter) OnError added in v0.0.15

func (e *ErrorEmitter) OnError(handler STTErrorHandler) func()

type FallbackAdapter

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

func NewFallbackAdapter

func NewFallbackAdapter(stts []STT) *FallbackAdapter

func NewFallbackAdapterWithOptions added in v0.0.15

func NewFallbackAdapterWithOptions(stts []STT, options FallbackAdapterOptions) *FallbackAdapter

func NewFallbackAdapterWithVAD added in v0.0.15

func NewFallbackAdapterWithVAD(stts []STT, vad vad.VAD) *FallbackAdapter

func NewFallbackAdapterWithVADAndOptions added in v0.0.15

func NewFallbackAdapterWithVADAndOptions(stts []STT, vad vad.VAD, options FallbackAdapterOptions) *FallbackAdapter

func (*FallbackAdapter) Capabilities

func (f *FallbackAdapter) Capabilities() STTCapabilities

func (*FallbackAdapter) Close added in v0.0.15

func (f *FallbackAdapter) Close() error

func (*FallbackAdapter) Label

func (f *FallbackAdapter) Label() string

func (*FallbackAdapter) Model added in v0.0.15

func (f *FallbackAdapter) Model() string

func (*FallbackAdapter) OnAvailabilityChanged added in v0.0.15

func (f *FallbackAdapter) OnAvailabilityChanged(handler AvailabilityChangedHandler) func()

func (*FallbackAdapter) OnError added in v0.0.15

func (f *FallbackAdapter) OnError(handler STTErrorHandler) func()

func (*FallbackAdapter) OnMetricsCollected added in v0.0.15

func (f *FallbackAdapter) OnMetricsCollected(handler STTMetricsHandler) func()

func (*FallbackAdapter) Prewarm added in v0.0.15

func (f *FallbackAdapter) Prewarm()

func (*FallbackAdapter) Provider added in v0.0.15

func (f *FallbackAdapter) Provider() string

func (*FallbackAdapter) Recognize

func (f *FallbackAdapter) Recognize(ctx context.Context, frames []*model.AudioFrame, language string) (*SpeechEvent, error)

func (*FallbackAdapter) Stream

func (f *FallbackAdapter) Stream(ctx context.Context, language string) (RecognizeStream, error)

type FallbackAdapterOptions added in v0.0.15

type FallbackAdapterOptions struct {
	MaxRetryPerSTT int
	AttemptTimeout time.Duration
	RetryInterval  time.Duration
}

func DefaultFallbackAdapterOptions added in v0.0.15

func DefaultFallbackAdapterOptions() FallbackAdapterOptions

type FallbackAllFailedError added in v0.0.15

type FallbackAllFailedError struct {
	Count    int
	Labels   []string
	Duration time.Duration
	Err      error
}

func (*FallbackAllFailedError) Error added in v0.0.15

func (e *FallbackAllFailedError) Error() string

func (*FallbackAllFailedError) Unwrap added in v0.0.15

func (e *FallbackAllFailedError) Unwrap() error

type InputEnding added in v0.0.15

type InputEnding interface {
	EndInput() error
}

type MetricsEmitter added in v0.0.15

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

func (*MetricsEmitter) EmitMetricsCollected added in v0.0.15

func (e *MetricsEmitter) EmitMetricsCollected(metrics *telemetry.STTMetrics)

func (*MetricsEmitter) OnMetricsCollected added in v0.0.15

func (e *MetricsEmitter) OnMetricsCollected(handler STTMetricsHandler) func()

type MultiSpeakerAdapter

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

func NewDefaultMultiSpeakerAdapter added in v0.0.15

func NewDefaultMultiSpeakerAdapter(stt STT) (*MultiSpeakerAdapter, error)

func NewMultiSpeakerAdapter

func NewMultiSpeakerAdapter(stt STT, detectPrimary bool, suppressBackground bool, primaryFormat string, backgroundFormat string, opt *PrimarySpeakerDetectionOptions) (*MultiSpeakerAdapter, error)

func (*MultiSpeakerAdapter) Capabilities

func (a *MultiSpeakerAdapter) Capabilities() STTCapabilities

func (*MultiSpeakerAdapter) Label

func (a *MultiSpeakerAdapter) Label() string

func (*MultiSpeakerAdapter) Model added in v0.0.15

func (a *MultiSpeakerAdapter) Model() string

func (*MultiSpeakerAdapter) Prewarm added in v0.0.15

func (a *MultiSpeakerAdapter) Prewarm()

func (*MultiSpeakerAdapter) Provider added in v0.0.15

func (a *MultiSpeakerAdapter) Provider() string

func (*MultiSpeakerAdapter) Recognize

func (a *MultiSpeakerAdapter) Recognize(ctx context.Context, frames []*model.AudioFrame, language string) (*SpeechEvent, error)

func (*MultiSpeakerAdapter) Stream

func (a *MultiSpeakerAdapter) Stream(ctx context.Context, language string) (RecognizeStream, error)

type PrimarySpeakerDetectionOptions

type PrimarySpeakerDetectionOptions struct {
	FrameSizeMs            int
	RMSBufferDuration      float64
	MinRMSSamples          int
	RMSSmoothingFactor     float64
	ThresholdMultiplier    float64
	DecayToEqualTime       float64
	ThresholdMinMultiplier float64
}

func DefaultPrimarySpeakerDetectionOptions

func DefaultPrimarySpeakerDetectionOptions() PrimarySpeakerDetectionOptions

type RecognitionUsage added in v0.0.15

type RecognitionUsage struct {
	AudioDuration float64 `json:"audio_duration"`
	InputTokens   int     `json:"input_tokens"`
	OutputTokens  int     `json:"output_tokens"`
}

func (*RecognitionUsage) UnmarshalJSON added in v0.0.52

func (u *RecognitionUsage) UnmarshalJSON(data []byte) error

type RecognizeStream

type RecognizeStream interface {
	PushFrame(frame *model.AudioFrame) error
	Flush() error
	Close() error
	Next() (*SpeechEvent, error)
}

type STT

type STT interface {
	Label() string
	Capabilities() STTCapabilities
	Stream(ctx context.Context, language string) (RecognizeStream, error)
	Recognize(ctx context.Context, frames []*model.AudioFrame, language string) (*SpeechEvent, error)
}

type STTCapabilities

type STTCapabilities struct {
	Streaming         bool   `json:"streaming"`
	InterimResults    bool   `json:"interim_results"`
	Diarization       bool   `json:"diarization"`
	AlignedTranscript string `json:"aligned_transcript"`
	OfflineRecognize  bool   `json:"offline_recognize"`
}

func (STTCapabilities) MarshalJSON added in v0.0.15

func (c STTCapabilities) MarshalJSON() ([]byte, error)

func (*STTCapabilities) UnmarshalJSON added in v0.0.15

func (c *STTCapabilities) UnmarshalJSON(data []byte) error

type STTError added in v0.0.15

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

func NewSTTError added in v0.0.15

func NewSTTError(label string, err error, recoverable bool) *STTError

func (*STTError) Error added in v0.0.15

func (e *STTError) Error() string

func (*STTError) MarshalJSON added in v0.0.15

func (e *STTError) MarshalJSON() ([]byte, error)

func (*STTError) UnmarshalJSON added in v0.0.52

func (e *STTError) UnmarshalJSON(data []byte) error

func (*STTError) Unwrap added in v0.0.15

func (e *STTError) Unwrap() error

type STTErrorHandler added in v0.0.15

type STTErrorHandler func(*STTError)

type STTMetricsHandler added in v0.0.15

type STTMetricsHandler func(*telemetry.STTMetrics)

type SampleRateGuard added in v0.0.15

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

func (*SampleRateGuard) Check added in v0.0.15

func (g *SampleRateGuard) Check(frame *model.AudioFrame) error

type SearchStream

type SearchStream interface {
	PushFrame(frame *model.AudioFrame) error
	Close() error
	Next() (*SpeechEvent, error)
}

type SpeechData

type SpeechData struct {
	Language         string         `json:"language"`
	Text             string         `json:"text"`
	StartTime        float64        `json:"start_time"`
	EndTime          float64        `json:"end_time"`
	Confidence       float64        `json:"confidence"`
	SpeakerID        string         `json:"speaker_id"`
	IsPrimarySpeaker *bool          `json:"is_primary_speaker"`
	Words            []TimedString  `json:"words"`
	SourceLanguages  []string       `json:"source_languages"`
	SourceTexts      []string       `json:"source_texts"`
	TargetLanguages  []string       `json:"target_languages"`
	TargetTexts      []string       `json:"target_texts"`
	Metadata         map[string]any `json:"metadata"`
}

func (SpeechData) MarshalJSON added in v0.0.52

func (d SpeechData) MarshalJSON() ([]byte, error)

func (*SpeechData) UnmarshalJSON added in v0.0.52

func (d *SpeechData) UnmarshalJSON(data []byte) error

type SpeechEvent

type SpeechEvent struct {
	Type             SpeechEventType   `json:"type"`
	RequestID        string            `json:"request_id"`
	Alternatives     []SpeechData      `json:"alternatives"`
	RecognitionUsage *RecognitionUsage `json:"recognition_usage"`
	SpeechStartTime  *float64          `json:"speech_start_time"`
	Interrupted      bool              `json:"-"`
}

func (SpeechEvent) MarshalJSON added in v0.0.15

func (e SpeechEvent) MarshalJSON() ([]byte, error)

func (*SpeechEvent) UnmarshalJSON added in v0.0.15

func (e *SpeechEvent) UnmarshalJSON(data []byte) error

type SpeechEventType

type SpeechEventType string
const (
	SpeechEventStartOfSpeech       SpeechEventType = "start_of_speech"
	SpeechEventInterimTranscript   SpeechEventType = "interim_transcript"
	SpeechEventPreflightTranscript SpeechEventType = "preflight_transcript"
	SpeechEventFinalTranscript     SpeechEventType = "final_transcript"
	SpeechEventRecognitionUsage    SpeechEventType = "recognition_usage"
	SpeechEventEndOfSpeech         SpeechEventType = "end_of_speech"
)

type SpeechStream added in v0.0.15

type SpeechStream = RecognizeStream

SpeechStream is a deprecated alias kept for LiveKit Agents API compatibility.

type StreamAdapter

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

StreamAdapter converts a non-streaming STT into a streaming STT by coupling it with a VAD. It buffers audio frames and sends them to the underlying STT Recognize method when the VAD detects speech.

func NewStreamAdapter

func NewStreamAdapter(stt STT, vad vad.VAD) *StreamAdapter

func (*StreamAdapter) Capabilities

func (a *StreamAdapter) Capabilities() STTCapabilities

func (*StreamAdapter) Label

func (a *StreamAdapter) Label() string

func (*StreamAdapter) Model added in v0.0.15

func (a *StreamAdapter) Model() string

func (*StreamAdapter) OnError added in v0.0.15

func (a *StreamAdapter) OnError(handler STTErrorHandler) func()

func (*StreamAdapter) OnMetricsCollected added in v0.0.15

func (a *StreamAdapter) OnMetricsCollected(handler STTMetricsHandler) func()

func (*StreamAdapter) Prewarm added in v0.0.15

func (a *StreamAdapter) Prewarm()

func (*StreamAdapter) Provider added in v0.0.15

func (a *StreamAdapter) Provider() string

func (*StreamAdapter) Recognize

func (a *StreamAdapter) Recognize(ctx context.Context, frames []*model.AudioFrame, language string) (*SpeechEvent, error)

func (*StreamAdapter) Stream

func (a *StreamAdapter) Stream(ctx context.Context, language string) (RecognizeStream, error)

func (*StreamAdapter) WrappedSTT added in v0.0.15

func (a *StreamAdapter) WrappedSTT() STT

type StreamAdapterWrapper added in v0.0.15

type StreamAdapterWrapper = streamAdapterWrapper

StreamAdapterWrapper is kept public for LiveKit Agents API compatibility.

type StreamTiming added in v0.0.15

type StreamTiming interface {
	StartTimeOffset() float64
	SetStartTimeOffset(offset float64)
	StartTime() float64
	SetStartTime(startTime float64)
}

type TimedString added in v0.0.15

type TimedString struct {
	Text            string  `json:"text"`
	StartTime       float64 `json:"start_time"`
	EndTime         float64 `json:"end_time"`
	Confidence      float64 `json:"confidence"`
	StartTimeOffset float64 `json:"start_time_offset"`
	SpeakerID       string  `json:"speaker_id"`
}

func (TimedString) MarshalJSON added in v0.0.52

func (s TimedString) MarshalJSON() ([]byte, error)

func (TimedString) String added in v0.0.52

func (s TimedString) String() string

func (*TimedString) UnmarshalJSON added in v0.0.52

func (s *TimedString) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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