C# 通过局域网发送声音或流声音
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/991766/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Send sound or stream sound over lan
提问by Gabe
I was wondering if there was a way to stream sound over a LAN. Can I have a client app connect to a server app and then receive a stream of sound from it. I'm sure it can be done, just not sure where to even start. Any suggestions? I was looking to do this with c#.
我想知道是否有办法通过 LAN 传输声音。我可以让客户端应用程序连接到服务器应用程序,然后从中接收声音流吗?我相信它可以做到,只是不知道从哪里开始。有什么建议?我正在寻找用 c# 来做到这一点。
I am not asking anyone to write it for me, just some on ideas or tricks that you may know, of just references or suggestions you may have.
我不是要求任何人为我写它,只是一些你可能知道的想法或技巧,只是你可能有的参考或建议。
回答by Alex Martelli
You probably want to implement RTSP, the standard "Real Time Streaming Protocol". According to MSDN, Silverlight kind-of-supports it (and several Windows Media Audio formats). However, the best-known open source libraries for RTSP are C++-- maybe you can call them from your C# code?
您可能想要实现RTSP,即标准的“实时流协议”。根据MSDN,Silverlight 有点支持它(以及几种 Windows Media Audio 格式)。但是,最著名的 RTSP 开源库是C++—— 也许您可以从 C# 代码中调用它们?
回答by Nifle
I believe you could use Windows media player on the client.
我相信您可以在客户端上使用 Windows 媒体播放器。
We use winmm.dll to play some music in one of our applications. And since the media player supports streaming you could probably solve your problem with a bit of fiddling.
我们使用 winmm.dll 在我们的一个应用程序中播放一些音乐。而且由于媒体播放器支持流媒体,您可能会通过一些摆弄来解决您的问题。
回答by Nifle
Another option could be to have your own Shoutcast serverand play that audio on the client after capturing it with a ShoutcastStream Class
另一种选择可能是拥有自己的 Shoutcast 服务器并在使用ShoutcastStream 类捕获音频后在客户端上播放该音频
回答by Derek Ekins
This is not a c# solution but may help with making a decision on what to use. http://pulseaudio.org/is used in a few linux distros now and you can install it on windows as well.
这不是 ac# 解决方案,但可能有助于决定使用什么。http://pulseaudio.org/现在在一些 linux 发行版中使用,您也可以在 Windows 上安装它。
From http://pulseaudio.org/wiki/WikiStart#Whatisit
来自http://pulseaudio.org/wiki/WikiStart#Whatisit
PulseAudio is a sound server for POSIX and Win32 systems. A sound server is basically a proxy for your sound applications. It allows you to do advanced operations on your sound data as it passes between your application and your hardware. Things like transferring the audio to a different machine, changing the sample format or channel count and mixing several sounds into one are easily achieved using a sound server.
PulseAudio has been tested on Linux, Solaris, FreeBSD, NetBSD, Windows 2000 and Windows XP. It should also run on all other POSIX and Windows systems, but may require new backends to handle their sound systems.
PulseAudio 是 POSIX 和 Win32 系统的声音服务器。声音服务器基本上是您的声音应用程序的代理。当声音数据在应用程序和硬件之间传递时,它允许您对声音数据进行高级操作。使用声音服务器可以轻松实现诸如将音频传输到另一台机器、更改样本格式或通道数以及将多个声音混合成一个之类的事情。
PulseAudio 已经在 Linux、Solaris、FreeBSD、NetBSD、Windows 2000 和 Windows XP 上进行了测试。它也应该在所有其他 POSIX 和 Windows 系统上运行,但可能需要新的后端来处理它们的声音系统。
Might be a good option depending on your scenario...
根据您的情况,可能是一个不错的选择...
回答by Dan
Though not C#, would this be an option? Netcat, mpg123, and rawplay create a solution. The author of this article serves audio from one machine to another.
虽然不是 C#,但这会是一个选择吗?Netcat、mpg123 和 rawplay 创建了一个解决方案。本文作者将音频从一台机器传送到另一台机器。
$(audioclient1):~$ nc -l -p 2345 | rawplay
$(audioserver):~$ mpg123 -s *.mp3 | nc (audioclient1) 2345
Later in the article, he shows how to use named pipes, serving audio to 6 machines on his LAN.
在文章的后面,他展示了如何使用命名管道,为他的 LAN 上的 6 台机器提供音频。
"use and abuse of pipes with audio data" http://www.debian-administration.org/articles/145
“使用和滥用带有音频数据的管道” http://www.debian-administration.org/articles/145