# README
Beep

A little package that brings sound to any Go application. Suitable for playback and audio-processing.
go get -u github.com/faiface/beep
Features
Beep is built on top of its Streamer interface, which is like io.Reader, but for audio. It was one of the best design decisions I've ever made and it enabled all the rest of the features to naturally come together with not much code.
- Decode and play WAV, MP3, OGG, and FLAC.
- Encode and save WAV.
- Very simple API. Limiting the support to stereo (two channel) audio made it possible to simplify the architecture and the API.
- Rich library of compositors and effects. Loop, pause/resume, change volume, mix, sequence, change playback speed, and more.
- Easily create new effects. With the
Streamer
interface, creating new effects is very easy. - Generate completely own artificial sounds. Again, the
Streamer
interface enables easy sound generation. - Very small codebase. The core is just ~1K LOC.
Tutorial
The Wiki contains a handful of tutorials for you to get started. They teach the fundamentals and advanced topics alike. Read them especially if you call speaker.Init
every time you play something.
- Hello, Beep!
- Composing and controlling
- To buffer, or not to buffer, that is the question
- Making own streamers
Examples
Speedy Player | Doppler Stereo Room |
---|---|
![]() | ![]() |
Dependencies
For playback, Beep uses Oto under the hood. Check its requirements to see what you need to install for building your application.
Running an already built application should work with no extra dependencies.
Licence
Projects using beep
# Packages
Package effects provides additional audio effects for the Beep library.
Package flac implements audio data decoding in FLAC format.
Package mp3 implements audio data decoding in MP3 format.
Package speaker implements playback of beep.Streamer values through physical speakers.
Package vorbis implements audio data decoding in oggvorbis format.
Package wav implements audio data decoding and encoding in WAVE format.
# Functions
Callback returns a Streamer, which does not stream any samples, but instead calls f the first time its Stream method is called.
Dup returns two Streamers which both stream the same data as the original s.
Iterate returns a Streamer which successively streams Streamers obtains by calling the provided g function.
Loop takes a StreamSeeker and plays it count times.
Mix takes zero or more Streamers and returns a Streamer which streams them mixed together.
NewBuffer creates a new empty Buffer which stores samples in the provided format.
Resample takes a Streamer which is assumed to stream at the old sample rate and returns a Streamer, which streams the data from the original Streamer resampled to the new sample rate.
ResampleRatio is same as Resample, except it takes the ratio of the old and the new sample rate, specifically, the old sample rate divided by the new sample rate.
Seq takes zero or more Streamers and returns a Streamer which streams them one by one without pauses.
Silence returns a Streamer which streams num samples of silence.
Take returns a Streamer which streams at most num samples from s.
# Interfaces
StreamCloser is a Streamer streaming from a resource which needs to be released, such as a file or a network connection.
Streamer is able to stream a finite or infinite sequence of audio samples.
StreamSeekCloser is a union of StreamSeeker and StreamCloser.
StreamSeeker is a finite duration Streamer which supports seeking to an arbitrary position.
# Type aliases
SampleRate is the number of samples per second.
StreamerFunc is a Streamer created by simply wrapping a streaming function (usually a closure, which encloses a time tracking variable).