Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing audio file with golang

Tags:

go

How one would play audio file in go language?

I have function and want sound to be played as notification when event happens.

I could not find anything about playing sound file in go lang just some web browser based music players but it wasnt helpful too much.

like image 917
Ramirex Avatar asked Feb 18 '15 18:02

Ramirex


2 Answers

You could use the PortAudio Go bindings (go get github.com/gordonklaus/portaudio) for this.

You will have to build or install PortAudio on your system. Consult http://portaudio.com/docs/v19-doxydocs/tutorial_start.html for this.

A complete example for playing back a sound file is located at https://github.com/gordonklaus/portaudio/blob/master/examples/play.go

like image 129
Peter Brennan Avatar answered Oct 17 '22 20:10

Peter Brennan


If it's an MP3 file, you can use go-mp3 Library. go-mp3 is popular library to play MP3; MP3 decoder is in pure Go.

Or this one, https://github.com/faiface/beep. Beep uses go-mp3 under the hood

like image 4
so-random-dude Avatar answered Oct 17 '22 19:10

so-random-dude