当服务器接收到请求时,如何使其播放声音?

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

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语言中播放声音:

如果你想要一个实际的例子,可以看看名为"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:

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.

huangapple
  • 本文由 发表于 2016年4月18日 02:31:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/36680524.html
匿名

发表评论

匿名网友

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

确定