使用Golang播放音频文件。

huangapple go评论88阅读模式
英文:

Playing audio file with golang

问题

如何在Go语言中播放音频文件?

当事件发生时,我想要通过通知的方式播放声音。

我在Go语言中找不到有关播放声音文件的信息,只找到了一些基于Web浏览器的音乐播放器,但对我来说并没有太大帮助。

英文:

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.

答案1

得分: 15

你可以使用PortAudio的Go绑定(go get github.com/gordonklaus/portaudio)来实现这个功能。

你需要在你的系统上构建或安装PortAudio。请参考http://portaudio.com/docs/v19-doxydocs/tutorial_start.html。

一个完整的播放音频文件的示例可以在https://github.com/gordonklaus/portaudio/blob/master/examples/play.go找到。

英文:

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

答案2

得分: 4

如果是一个MP3文件,你可以使用go-mp3库。go-mp3是一个流行的用于播放MP3的库;MP3解码器是用纯Go编写的。

或者你可以使用这个库,https://github.com/faiface/beep。Beep在内部使用了go-mp3。

英文:

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

huangapple
  • 本文由 发表于 2015年2月19日 02:57:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/28591664.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定