英文:
How to make server play sound when receiving request
问题
如果你正在使用基于Go的服务器,你可以通过以下方式实现在接收到请求时播放声音片段的功能。首先,你需要在服务器端编写代码来处理请求并播放声音。然后,你可以使用Go的内置库或第三方库来实现播放声音的功能。具体的实现方式取决于你使用的服务器框架和音频播放库。你可以在服务器接收到请求时调用播放声音的函数或方法,以实现在浏览器窗口中播放声音的效果。
英文:
I want to make a server play a soundbyte every time it receives a request. Is there a way to do this if I'm using a Go based server? The idea would be the server is hosting a browser window, it receives a request and the browser goes 'ping!'.
答案1
得分: 1
这取决于你希望代码在哪个操作系统上运行。据我所知,目前没有通用的跨平台解决方案可以在Go语言中播放声音:
- 在Linux上,你可能需要依赖Pulse Audio,并使用像github.com/mesilliac/pulse-simple这样的包。
- 在Windows和Mac上,你可以使用PortAudio,并使用像github.com/gordonklaus/portaudio这样的包。
如果你想要一个实际的例子,可以看看名为"moggio"的基于Go语言的多源音乐播放器项目,它可以在Linux、Mac和Windows上播放音频。该项目的GitHub链接是github.com/mjibson/moggio。
你可以查看moggio的output包。在那里,你会找到moggio用于在Linux、Windows和Mac上播放音乐的代码。
英文:
It depends on which operating system you want the code to work. Afaik there is no generic cross-platform solution for playing sound from go:
- On Linux you might need to rely on Pulse Audio with a package such as github.com/mesilliac/pulse-simple
- On Windows and Mac you could use PortAudio with a package such as github.com/gordonklaus/portaudio
If you want a practical example there is a go-based multi-source music player project called "moggio" at github.com/mjibson/moggio that plays audio from multiple sources on Linux, Mac and Windows.
You can have a look at the github.com/mjibson/moggio/output package. There you will find the code that moggio used to play music on Linux, Windows and Mac.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论