audio

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 6 Imported by: ? 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 utilities for converting between PCM and μ-law audio formats.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculatePCMDuration

func CalculatePCMDuration(audioFormat *audiopb.Format, dataSize int) (time.Duration, error)

CalculatePCMDuration calculates the duration of audio data given its parameters. dataSize is the total size of audio data in bytes. sampleRate is the number of samples per second (Hz). channels is the number of audio channels (1 for mono, 2 for stereo). bitsPerSample is the number of bits per sample (e.g., 16 for PCM16).

func CalculateWAVDuration

func CalculateWAVDuration(bytes []byte) (time.Duration, error)

func Mulaw8ToPCM16

func Mulaw8ToPCM16(mulaw []byte) []byte

MulawToPCM converts μ-law encoded audio to 16-bit PCM (little-endian). Input: μ-law bytes (8-bit samples) Output: PCM bytes (16-bit samples, little-endian)

func PCM16ToMulaw8

func PCM16ToMulaw8(pcmBytes []byte) []byte

PCMToMulaw converts 16-bit PCM to μ-law encoded audio. Input: PCM bytes (16-bit samples, little-endian) Output: μ-law bytes (8-bit samples)

func PCMToWAV

func PCMToWAV(pcmData []byte, audioFormat *audiopb.Format) []byte

PCMToWAV converts raw PCM audio to WAV format pcmData: PCM samples in the format specified by audioFormat audioFormat: specifies sample rate, number of channels, and bits per sample

func ResamplePCM16

func ResamplePCM16(input []byte, fromRate, toRate int32) []byte

ResamplePCM16 resamples 16-bit PCM audio from one sample rate to another using simple linear interpolation (suitable for downsampling)

func WAVToPCM16

func WAVToPCM16(wavData []byte) (pcmData []byte, sampleRate int32, numChannels int16, err error)

WAVToPCM16 extracts raw 16-bit PCM audio data from a WAV file. Returns the PCM data, sample rate, number of channels, and any error. The function validates the WAV header and ensures it contains 16-bit PCM audio.

Types

This section is empty.

Jump to

Keyboard shortcuts

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