stt

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TurnStartOfTurn    = "start_of_turn"
	TurnUpdate         = "update"
	TurnEagerEndOfTurn = "eager_end_of_turn"
	TurnResumed        = "turn_resumed"
	TurnEndOfTurn      = "end_of_turn"
	TurnUtteranceEnd   = "utterance_end"
)

Turn event kinds. The Deepgram Flux state machine emits the first five; Deepgram v1 emits only TurnUtteranceEnd.

Variables

This section is empty.

Functions

This section is empty.

Types

type AzureTranscriber added in v0.2.0

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

AzureTranscriber streams audio to Azure Speech Services real-time STT over WebSocket.

func NewAzure added in v0.2.0

func NewAzure(region string, log *slog.Logger) *AzureTranscriber

func (*AzureTranscriber) Running added in v0.2.0

func (t *AzureTranscriber) Running() bool

func (*AzureTranscriber) Start added in v0.2.0

func (t *AzureTranscriber) Start(ctx context.Context, reader io.Reader, apiKey string, opts Options, cb TranscriptCallback) error

func (*AzureTranscriber) Stop added in v0.2.0

func (t *AzureTranscriber) Stop()

type DeepgramTranscriber

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

DeepgramTranscriber streams audio to Deepgram real-time STT over WebSocket.

func NewDeepgram

func NewDeepgram(cfg providercfg.Deepgram, log *slog.Logger) *DeepgramTranscriber

func (*DeepgramTranscriber) Finalize added in v0.12.0

func (t *DeepgramTranscriber) Finalize(ctx context.Context) error

Finalize asks Deepgram for a final transcript covering the audio buffered so far and keeps the socket OPEN — unlike the CloseStream frame sendLoop writes at teardown, which flushes AND ends the session. Fire-and-forget: the flushed final arrives through the existing recvLoop callback, and a silent segment yields no transcript at all because empty transcripts are dropped before the callback.

func (*DeepgramTranscriber) Running

func (t *DeepgramTranscriber) Running() bool

func (*DeepgramTranscriber) Start

func (t *DeepgramTranscriber) Start(ctx context.Context, reader io.Reader, apiKey string, opts Options, cb TranscriptCallback) error

func (*DeepgramTranscriber) Stop

func (t *DeepgramTranscriber) Stop()

type ElevenLabsTranscriber

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

ElevenLabsTranscriber streams audio to ElevenLabs real-time STT over WebSocket.

func (*ElevenLabsTranscriber) Running

func (t *ElevenLabsTranscriber) Running() bool

Running returns whether the transcriber is active.

func (*ElevenLabsTranscriber) Start

func (t *ElevenLabsTranscriber) Start(ctx context.Context, reader io.Reader, apiKey string, opts Options, cb TranscriptCallback) error

Start connects to ElevenLabs STT and streams PCM from reader. It blocks until the context is cancelled or an error occurs.

func (*ElevenLabsTranscriber) Stop

func (t *ElevenLabsTranscriber) Stop()

Stop cancels the running transcription.

type Finalizer added in v0.12.0

type Finalizer interface {
	Finalize(ctx context.Context) error
}

Finalizer is implemented by providers that can flush the server-side audio buffer mid-stream, forcing a final transcript for what has been spoken so far WITHOUT closing the session. Optional: only Deepgram supports it today, so callers must type-assert rather than assume every Provider has it. Deepgram Flux does NOT — /v2/listen has no Finalize message.

type FluxTranscriber added in v0.12.0

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

FluxTranscriber streams audio to Deepgram Flux (/v2/listen) over WebSocket. Flux reports a conversational turn state machine rather than plain interim and final segments. It deliberately does NOT implement Finalizer: /v2 has no Finalize message.

func NewDeepgramFlux added in v0.12.0

func NewDeepgramFlux(cfg providercfg.Deepgram, log *slog.Logger) *FluxTranscriber

func (*FluxTranscriber) Running added in v0.12.0

func (t *FluxTranscriber) Running() bool

func (*FluxTranscriber) Start added in v0.12.0

func (t *FluxTranscriber) Start(ctx context.Context, reader io.Reader, apiKey string, opts Options, cb TranscriptCallback) error

func (*FluxTranscriber) Stop added in v0.12.0

func (t *FluxTranscriber) Stop()

type Options

type Options struct {
	Language string // ISO-639-1 language code (default "en")
	Partial  bool   // emit partial transcripts

	Model string // provider model override (v1 "nova-3", flux "flux-general-en")

	// Deepgram v1. Pointers because 0 is meaningful (endpointing=0 disables
	// endpointing) and must be distinguishable from "not set".
	Endpointing    *int
	UtteranceEndMs *int

	// Deepgram Flux.
	EagerEOTThreshold *float64
	EOTThreshold      *float64
	EOTTimeoutMs      *int
	LanguageHints     []string

	Keyterms []string

	// Optional sinks. When OnTranscript is non-nil it supersedes the
	// TranscriptCallback passed to Start.
	OnTranscript TranscriptDetailCallback
	OnTurn       TurnCallback
}

Options configures the transcription session.

type Provider

type Provider interface {
	Start(ctx context.Context, reader io.Reader, apiKey string,
		opts Options, cb TranscriptCallback) error
	Stop()
	Running() bool
}

Provider is the common interface for speech-to-text backends.

type SpeechmaticsTranscriber added in v0.13.0

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

SpeechmaticsTranscriber streams audio to the Speechmatics Realtime v2 API over WebSocket.

func NewSpeechmatics added in v0.13.0

func NewSpeechmatics(url string, log *slog.Logger) *SpeechmaticsTranscriber

NewSpeechmatics builds a transcriber for the given endpoint. An empty url selects the default SaaS region; a self-hosted container or another region is reached by passing its wss:// address.

func (*SpeechmaticsTranscriber) Finalize added in v0.13.0

func (t *SpeechmaticsTranscriber) Finalize(ctx context.Context) error

Finalize closes the current utterance and keeps the socket OPEN — unlike the EndOfStream frame sendLoop writes at teardown, which flushes AND ends the session. Fire-and-forget: the forced final and its EndOfUtterance arrive through the existing recvLoop callbacks.

func (*SpeechmaticsTranscriber) Running added in v0.13.0

func (t *SpeechmaticsTranscriber) Running() bool

func (*SpeechmaticsTranscriber) Start added in v0.13.0

func (t *SpeechmaticsTranscriber) Start(ctx context.Context, reader io.Reader, apiKey string, opts Options, cb TranscriptCallback) error

func (*SpeechmaticsTranscriber) Stop added in v0.13.0

func (t *SpeechmaticsTranscriber) Stop()

type TranscriptCallback

type TranscriptCallback func(text string, isFinal bool)

TranscriptCallback is called for each transcript result.

type TranscriptDetailCallback added in v0.12.0

type TranscriptDetailCallback func(TranscriptEvent)

TranscriptDetailCallback receives TranscriptEvent values.

type TranscriptEvent added in v0.12.0

type TranscriptEvent struct {
	Text        string
	IsFinal     bool
	SpeechFinal bool // the speaker stopped, not just a finalized segment
	// AudioStart and AudioEnd are where in the stream this was said, in seconds
	// from the first audio the transcriber was given, zero when the provider
	// reports no timing. Not the callback's arrival time: a turn detector emits
	// a turn when it ends, so arrival lands after the words were spoken.
	AudioStart float64
	AudioEnd   float64
}

TranscriptEvent is the richer transcript payload delivered through Options.OnTranscript.

type TurnCallback added in v0.12.0

type TurnCallback func(TurnEvent)

TurnCallback receives TurnEvent values.

type TurnEvent added in v0.12.0

type TurnEvent struct {
	Event               string // one of the Turn* constants
	TurnIndex           int
	Transcript          string
	EndOfTurnConfidence float64
	AudioWindowStart    float64
	AudioWindowEnd      float64
	LastWordEnd         float64 // Deepgram v1 UtteranceEnd only
	Words               []TurnWord
	Languages           []string
}

TurnEvent carries a turn-boundary signal. Times are seconds, as the provider sends them; the API layer converts to milliseconds.

type TurnWord added in v0.12.0

type TurnWord struct {
	Word       string
	Confidence float64
	Start      float64 // seconds
	End        float64 // seconds
}

TurnWord is a single word within a turn, with its timing and confidence.

Jump to

Keyboard shortcuts

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