audio

package
v0.81.12 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 3 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 provides the shared PCM audio primitives for the SpeechKit capture format: 16kHz S16 mono constants, WAV framing, duration math, and RMS level estimation.

Stability: Stable — no breaking change without a minor version bump and a changelog callout.

Index

Constants

View Source
const (
	SampleRate     = 16000
	Channels       = 1
	BitsPerSample  = 16
	BytesPerSample = BitsPerSample / 8
)

PCM format of every SpeechKit capture buffer: 16 kHz sample rate, one channel, signed 16-bit little-endian samples, so a second of audio is SampleRate*BytesPerSample (32000) bytes.

Variables

This section is empty.

Functions

func NormalizePCM16Mono added in v0.76.6

func NormalizePCM16Mono(pcm []byte, srcRate, srcCh, dstRate int) ([]byte, error)

NormalizePCM16Mono downmixes multi-channel S16LE PCM to mono and resamples it to dstRate.

func PCMDurationSecs

func PCMDurationSecs(pcm []byte) float64

PCMDurationSecs returns the duration of PCM audio in seconds.

func PCMLevel

func PCMLevel(pcm []byte) float64

PCMLevel estimates a normalized RMS level from 16-bit PCM samples.

func PCMToWAV

func PCMToWAV(pcm []byte) []byte

PCMToWAV wraps raw 16kHz S16 Mono PCM data in a WAV header.

func ParseWAV added in v0.76.6

func ParseWAV(raw []byte) (pcm []byte, sampleRate, channels int, err error)

ParseWAV returns the S16LE data chunk of a PCM WAV file with its native sample rate and channel count.

func SynthesizedToPCM16Mono added in v0.76.6

func SynthesizedToPCM16Mono(raw []byte, format string, sourceRate, dstRate int) ([]byte, error)

SynthesizedToPCM16Mono converts one synthesized speech payload (WAV, MP3 or raw S16LE PCM at sourceRate) to S16LE mono PCM at dstRate, the shape a raw PCM audio wire expects. Formats it cannot decode, such as Opus, fail rather than pass through as unplayable bytes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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