asr

package
v0.0.0-...-7ec3357 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultChunkSeconds and DefaultChunkOverlapSeconds are the out-of-the-box
	// window and overlap sizes when a caller leaves them unset.
	DefaultChunkSeconds        = 300
	DefaultChunkOverlapSeconds = 15
)

Variables

View Source
var DebugMode bool

DebugMode enables verbose logging

View Source
var ErrAudioTooLong = errors.New("audio too long for a single pass; enable long-audio mode")

ErrAudioTooLong is returned when long-audio mode is off and the input exceeds what the model can process in a single pass.

View Source
var ErrUnsupportedAudio = errors.New("unsupported audio")

ErrUnsupportedAudio is returned when the input is neither a parsable WAV nor convertible via ffmpeg (either because ffmpeg is disabled/missing or because ffmpeg itself rejected the input). Callers can use errors.Is to detect this condition and map it to HTTP 400.

Functions

This section is empty.

Types

type BoundaryConfig

type BoundaryConfig struct {
	DisableVAD   bool
	DisableMel   bool
	VADModelPath string
}

BoundaryConfig tunes how the emission boundary inside each chunk overlap is chosen. By default the cascade is VAD -> mel energy -> midpoint; the disable flags drop the earlier layers so the cascade falls through to the next one. VADModelPath points at the Silero VAD ONNX file; when empty the caller resolves it to silero_vad.onnx inside the models directory.

type ChunkConfig

type ChunkConfig struct {
	Enabled        bool
	Seconds        int
	OverlapSeconds int
}

ChunkConfig sets the sliding-window sizes that keep long audio within the model's frame limit. Zero values fall back to the package defaults. Enabled turns on the windowing; when off, audio over the model limit is rejected.

type Config

type Config struct {
	ModelType         string `json:"model_type"`
	FeaturesSize      int    `json:"features_size"`
	SubsamplingFactor int    `json:"subsampling_factor"`
}

type FFmpegConfig

type FFmpegConfig struct {
	// Enabled toggles ffmpeg-backed conversion.
	Enabled bool

	// BinaryPath is the resolved absolute path to the ffmpeg executable.
	BinaryPath string

	// Timeout bounds the wall-clock time of a single conversion.
	Timeout time.Duration
}

FFmpegConfig controls optional ffmpeg-backed conversion of non-WAV inputs.

When Enabled is true, loadAudio will attempt to transcode unknown inputs to 16 kHz mono PCM WAV via an external ffmpeg binary. When Enabled is false (the default outside of environments where ffmpeg was found), only WAV input is accepted.

type GPUConfig

type GPUConfig struct {
	Provider Provider
	DeviceID int
}

GPUConfig selects the execution provider and, for GPU providers, the device.

type MelFilterbank

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

MelFilterbank computes mel-scale filterbank features

func NewMelFilterbank

func NewMelFilterbank(nMels, sampleRate int) *MelFilterbank

NewMelFilterbank creates a new mel filterbank extractor Using NeMo default parameters for 128 mel features

func (*MelFilterbank) Extract

func (m *MelFilterbank) Extract(samples []float32) [][]float32

Extract computes mel filterbank features from audio samples

func (*MelFilterbank) FramesPerSecond

func (m *MelFilterbank) FramesPerSecond() int

FramesPerSecond returns how many mel frames one second of audio yields, set by the hop length and sample rate. It ties frame counts to wall-clock time so chunk sizes can be configured in seconds.

func (*MelFilterbank) HopLength

func (m *MelFilterbank) HopLength() int

HopLength returns the hop between mel frames in samples. It maps a mel-frame index to a sample offset (frame * hopLength), which the VAD boundary oracle uses to slice the waveform for an overlap region.

type Options

type Options struct {
	FFmpeg   FFmpegConfig
	GPU      GPUConfig
	Chunk    ChunkConfig
	Boundary BoundaryConfig
}

Options groups optional knobs passed to NewTranscriber. Zero values keep the previous behavior: WAV-only input, no ffmpeg conversion, CPU inference, default chunk sizes, and the full boundary stack (VAD then mel then midpoint).

type Provider

type Provider string

Provider selects the ONNX Runtime execution provider used for inference.

const (
	ProviderCPU  Provider = "cpu"
	ProviderCUDA Provider = "cuda"
)

func ParseProvider

func ParseProvider(s string) (Provider, error)

ParseProvider normalizes a user-supplied provider string. An empty value defaults to CPU. Unknown values are rejected so a misconfiguration fails loudly at startup instead of silently falling back.

type Transcriber

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

func NewTranscriber

func NewTranscriber(modelsDir string, workers int, opts Options) (*Transcriber, error)

NewTranscriber loads models and initializes the decoder worker pool. When opts.FFmpeg.Enabled is true and the ffmpeg binary is resolvable, non-WAV inputs will be transcoded on the fly. Otherwise, only WAV is accepted and non-WAV inputs return ErrUnsupportedAudio.

func (*Transcriber) Close

func (t *Transcriber) Close()

Close releases the encoder session, all pool workers, and the ONNX Runtime environment. Safe to call after requests have run.

func (*Transcriber) Transcribe

func (t *Transcriber) Transcribe(ctx context.Context, audioData []byte, format, language string) (string, error)

func (*Transcriber) TranscribeStream

func (t *Transcriber) TranscribeStream(ctx context.Context, audioData []byte, format, language string, emit func(delta string)) (string, error)

TranscribeStream behaves like Transcribe but invokes emit with each new chunk of decoded text as soon as the underlying TDT decoder produces it. Concatenating all emitted deltas reproduces the transcript verbatim, before the final whitespace normalization. The returned full transcript (also sent as transcript.text.done) is that same text with leading/trailing whitespace trimmed and runs of spaces collapsed, so it may differ from the raw delta concatenation by surrounding/duplicate spaces only. emit is always called from the same goroutine that called TranscribeStream.

Jump to

Keyboard shortcuts

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