go-miniflac is a Go binding for the miniflac C library. The following is the miniflac description from its author, @jprjr.
A single-file C library for decoding FLAC streams. Does not use any C library functions, does not allocate any memory.
go-miniflac has a very simple interface, one function and one struct, and has zero external dependencies. However, Cgo must be enabled to compile this package.
// Decode parses a FLAC byte slice and returns a [Waveform].
func Decode(flacData []byte) (*Waveform, error)
// Waveform represents decoded PCM audio data. 🎶
type Waveform struct {
// Channels is the number of audio channels (e.g., 1 for mono, 2 for stereo).
Channels int
// SampleRate is the number of samples per second (e.g., 44100 Hz).
SampleRate int
// Samples contains the interleaved audio data.
Samples []int
// SourceBitDepth is the original bit depth of the audio.
SourceBitDepth int
}
How to convert a FLAC file to a WAV file using go-audio/wav
Check out examples/flac-to-wav
Many useful commands are in two Taskfile.yml
files: Taskfile.yml and examples/Taskfile.yml. To run the tasks, you need to install go-task/task, which works similarly to GNU Make.
Check out the Dockerfile for an example of using golang:1.25-bookworm
and gcr.io/distroless/base-debian12
to run go-miniflac
with Cgo enabled.
docker build -t cowork-ai/go-miniflac .
cat ./testdata/Sample_BeeMoved_96kHz24bit.flac | docker run --rm -i cowork-ai/go-miniflac | ffplay -autoexit -i pipe:
Note that the gcr.io/distroless/static-debian12
image does not work because it lacks glibc
.