audio

package
v0.73.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 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

Overview

Package audio normalizes inbound audio payloads to the Framework kernel's canonical PCM format (16 kHz, signed 16-bit little-endian, mono) before they enter the STT router. Every client format that the server accepts is converted here; the kernel itself never sees raw MP3, Opus, or stereo input.

Index

Constants

View Source
const TargetBytesPerSample = 2

TargetBytesPerSample is 16-bit signed little-endian.

View Source
const TargetChannels = 1

TargetChannels is the canonical channel count (mono) used by every STT provider.

View Source
const TargetSampleRate = 16000

TargetSampleRate is the canonical rate every STT provider expects.

Variables

View Source
var ErrDecodedAudioTooLarge = errors.New("audio: decoded audio exceeds configured duration limit")

ErrDecodedAudioTooLarge is wrapped by DecodeLimitError when a compressed payload expands beyond the configured decoded-duration ceiling.

View Source
var ErrFFmpegUnavailable = errors.New("audio: ffmpeg not available — install ffmpeg or send WAV/MP3/raw-PCM instead")

ErrFFmpegUnavailable is returned when a payload requires ffmpeg but the binary is not on PATH. Container deployments include ffmpeg; bare-metal dev environments may need to install it.

View Source
var ErrUnsupportedFormat = errors.New("audio: unsupported format (supported: wav, mp3, raw pcm16 @ 16kHz mono, webm/opus, ogg/opus)")

ErrUnsupportedFormat is returned when neither the Content-Type nor the payload's magic bytes identify a format we can decode.

Functions

This section is empty.

Types

type DecodeLimitError added in v0.42.0

type DecodeLimitError struct {
	MaxSeconds  int
	DurationMs  int64
	MaxBytes    int64
	ActualBytes int64
}

DecodeLimitError carries the configured ceiling and observed decoded size/duration for callers that need to map the failure to HTTP 413.

func (*DecodeLimitError) Error added in v0.42.0

func (e *DecodeLimitError) Error() string

func (*DecodeLimitError) Unwrap added in v0.42.0

func (e *DecodeLimitError) Unwrap() error

type DecodeLimits added in v0.42.0

type DecodeLimits struct {
	MaxDecodedAudioSeconds int
}

DecodeLimits bounds resource amplification after compressed/container audio is decoded to PCM. Zero values preserve the historical unbounded behavior for internal callers; server handlers pass the production limit from config.

type DecodedAudio

type DecodedAudio struct {
	PCM          []byte
	SourceFormat string
	SourceRate   int
	SourceCh     int
	DurationMs   int64
}

DecodedAudio is the canonical 16 kHz, mono, S16LE PCM payload plus the metadata recovered from the source.

func Decode

func Decode(raw []byte, contentType string) (*DecodedAudio, error)

Decode consumes raw bytes and a client-provided Content-Type and returns a canonical DecodedAudio ready for the STT router. contentType may be empty; in that case magic-byte sniffing is attempted.

func DecodeReader

func DecodeReader(r io.Reader, contentType string, maxBytes int64) (*DecodedAudio, error)

DecodeReader is a convenience wrapper that buffers a reader (capped at maxBytes) and then invokes Decode.

func DecodeWithLimits added in v0.42.0

func DecodeWithLimits(ctx context.Context, raw []byte, contentType string, limits DecodeLimits) (*DecodedAudio, error)

DecodeWithLimits consumes raw bytes and enforces optional decoded-audio limits while normalizing to canonical PCM.

Jump to

Keyboard shortcuts

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