Go library for decoding and playing audio files. Supports multiple codecs with a unified interface.
| Format | Decoder | CGO |
|---|---|---|
| WAV | go-wav | No |
| MP3 | go-mp3 | No |
| FLAC | go-flac | Yes (libflac) |
| Vorbis | oggvorbis | No |
| Opus | go-opus | Yes (libopus) |
- decoder - Unified
AudioDecoderinterface with codec-specific implementations - audioplayer - PortAudio-based playback with ringbuffer (SPSC pattern, callback mode)
- audio -
AudioStreaminterface for streaming pipelines - audioframe - PCM audio frame type with format metadata
- audioframeringbuffer - Lock-free ring buffer for audio frames
- types - Shared types (format, song info, playlist, playback status)
- oggutil - OGG container utilities
import (
"github.com/drgolem/audiokit/pkg/decoder"
"github.com/drgolem/audiokit/pkg/audioplayer"
)
// Decode any supported format
dec, err := decoder.NewDecoder("song.flac")
defer dec.Close()
rate, channels, bps := dec.GetFormat()
// Play audio
player := audioplayer.New(deviceIdx, 64, 1024, 4096)
player.SetDecoder(dec, "song.flac")
player.Play()
player.Wait()
player.Stop()A complete example audio player is included:
go run ./internal/examples/player song.flac
go run ./internal/examples/player -d 1 -v music.mp3
go run ./internal/examples/player -h # show all flagsFlags: -d device index, -c buffer capacity, -p PA frames, -s samples per frame, -v verbose.
CGO-dependent codecs require native libraries:
# macOS
brew install flac libogg opus portaudio
# Ubuntu/Debian
apt-get install libflac-dev libogg-dev libopus-dev libopusfile-dev portaudio19-dev
# Raspberry Pi (Raspbian/Raspberry Pi OS)
sudo apt-get install libflac-dev libogg-dev libopus-dev libopusfile-dev portaudio19-dev libasound2-devMIT