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.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With