Documentation
¶
Overview ¶
Package audio provides A-law (G.711 PCMA) encode/decode for 16-bit mono PCM.
Package audio provides minimal audio processing utilities for the Voxray system, focusing on 16-bit PCM mono audio formats used by STT and TTS services.
Package audio provides mix and interleave helpers for 16-bit mono PCM.
Package audio provides optional sample rate conversion (resample) for 16-bit mono PCM.
Package audio provides μ-law (G.711 PCMU) encode/decode for 16-bit mono PCM.
Package audio provides WAV decoding utilities.
Index ¶
- Constants
- func DecodeALaw(alaw []byte) []byte
- func DecodeULaw(ulaw []byte) []byte
- func DecodeWAVToPCM(wav []byte) (pcm []byte, sampleRate int, err error)
- func EncodeALaw(pcm []byte) []byte
- func EncodeULaw(pcm []byte) []byte
- func GenerateDTMFPCM(sampleRate int, key string, toneDuration, gapDuration float64) ([]byte, error)
- func InterleaveStereo(left, right []byte) []byte
- func MixMono(user, bot []byte) []byte
- func PCM16MonoNumFrames(bytes []byte) int
- func Resample16Mono(in []byte, inRate, outRate int, out []byte) []byte
- func Resample16MonoAlloc(in []byte, inRate, outRate int) []byte
- func WritePCM16MonoWAV(path string, pcm []byte, sampleRate int) error
- type Frame
- type Stream
Constants ¶
const ( // DefaultInSampleRate is the typical sample rate for STT input (16kHz). DefaultInSampleRate = 16000 // DefaultOutSampleRate is the typical sample rate for TTS output (24kHz). DefaultOutSampleRate = 24000 )
Default audio configuration constants for the Voxray system.
Variables ¶
This section is empty.
Functions ¶
func DecodeALaw ¶
DecodeALaw converts A-law (PCMA) bytes to 16-bit little-endian PCM. Output length is len(alaw)*2.
func DecodeULaw ¶
DecodeULaw converts μ-law (PCMU) bytes to 16-bit little-endian PCM. Output length is len(ulaw)*2.
func DecodeWAVToPCM ¶
DecodeWAVToPCM extracts raw 16-bit little-endian PCM and sample rate from WAV bytes. Returns (pcm, sampleRate, nil) or (nil, 0, error) for invalid/unsupported WAV. Supports standard PCM WAV with "fmt " and "data" chunks.
func EncodeALaw ¶
EncodeALaw converts 16-bit little-endian PCM to A-law (PCMA) bytes. len(pcm) must be even; output length is len(pcm)/2.
func EncodeULaw ¶
EncodeULaw converts 16-bit little-endian PCM to μ-law (PCMU) bytes. len(pcm) must be even; output length is len(pcm)/2.
func GenerateDTMFPCM ¶
GenerateDTMFPCM generates 16-bit little-endian mono PCM for a DTMF key. key: "0"-"9", "star", "pound". toneDuration and gapDuration are in seconds.
func InterleaveStereo ¶
InterleaveStereo interleaves two 16-bit mono buffers as left, right, left, right, ... If lengths differ, the shorter channel is padded with zeros so both have the same length. Returns a new slice of length 4*max(samples in left, samples in right).
func MixMono ¶
MixMono mixes two 16-bit little-endian mono PCM buffers by averaging samples. If lengths differ, the shorter buffer is padded with zeros to match the longer. Returns a new slice of length max(len(user), len(bot)).
func PCM16MonoNumFrames ¶
PCM16MonoNumFrames calculates the number of audio frames in a PCM16 mono buffer. Since each frame is 16 bits (2 bytes), the number of frames is total bytes divided by 2.
func Resample16Mono ¶
Resample16Mono converts 16-bit mono PCM from inRate to outRate using linear interpolation. It performs a sample rate conversion to match the target service's requirements. in and out can be the same slice if inRate == outRate (no-op). Otherwise out must have capacity for the resampled length: len(out) >= len(in) * outRate / inRate (rounded up).
func Resample16MonoAlloc ¶
Resample16MonoAlloc returns a new slice with 16-bit mono PCM resampled from inRate to outRate. It is a convenience wrapper around Resample16Mono that handles allocation.