在 C# 中捕获声音输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1292076/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:45:09  来源:igfitidea点击:

Capture Sound Output In C#

c#audio

提问by Sean James

I'm trying to build a program in C# that will allow me to stream audio and video from one computer, over the network, to another computer, which is hooked up to a bunch of video/audio equipment (projector, speakers, etc). Ideally, I'd like to be able to capture this data directly from the "presenter" computer without it having to plug into anything.

我正在尝试用 C# 构建一个程序,它允许我通过网络将音频和视频从一台计算机流式传输到另一台计算机,该计算机连接到一堆视频/音频设备(投影仪、扬声器等) . 理想情况下,我希望能够直接从“演示者”计算机捕获这些数据,而无需插入任何东西。

The video, streaming, and re-displaying on the "output" computer is all working well, but I can't seem to find a good way to capture audio output without the need for a cable plugged in to the headphone Hyman and wired to the other computer. The whole point of this program is to allow this to be done wirelessly, so this is kind of a problem. To sum up, I'm looking for some sort of C# interface that will allow me to capture the sound output on a windows machine, as though I had plugged something into the headphone Hyman.

“输出”计算机上的视频、流媒体和重新显示都运行良好,但我似乎无法找到一种在不需要将电缆插入耳机插孔并连接到耳机插孔的情况下捕获音频输出的好方法另一台电脑。该程序的全部意义在于允许以无线方式完成此操作,因此这是一个问题。总而言之,我正在寻找某种 C# 接口,它允许我在 Windows 机器上捕获声音输出,就好像我已将某些东西插入耳机插孔一样。

Thanks in advance for any help.

在此先感谢您的帮助。

采纳答案by Magnus Johansson

In Windows, the audio card manufacturers could choose to supply a "what you hear" input stream in order for you to capture the output. If your sound card/driver doesn't have this feature, you could try to use the Virtual Audio Cableto perform the same thing.

在 Windows 中,声卡制造商可以选择提供“您所听到的”输入流,以便您捕获输出。如果您的声卡/驱动程序没有此功能,您可以尝试使用虚拟音频线来执行相同的操作。

In Windows 7, there's a new functionality that allows you to listen to / capture any input stream directly.

在 Windows 7 中,有一项新功能可让您直接收听/捕获任何输入流。

回答by RC1140

Have a look at the code in this article , it needs to be modified quite a bit to be able to stream the output over the network , but that should not be hard enough. http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=19102

看看这篇文章中的代码,它需要修改很多才能通过网络流式传输输出,但这还不够难。http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=19102

回答by Sebastian Gray

If you already have the Video side figured out; NAudio is a good way to handle the Audio component.

如果您已经弄清楚了视频方面;NAudio 是处理音频组件的好方法。

Assuming we break the task in to the recording and then the receiving and playing components then the following should help you with each side;

假设我们将任务分解为录音,然后是接收和播放组件,那么以下内容应该对每一方都有帮助;

The recording: http://opensebj.blogspot.com/2009/04/naudio-tutorial-5-recording-audio.html

录音:http: //opensebj.blogspot.com/2009/04/naudio-tutorial-5-recording-audio.html

The receiving and playing: Play audio from a stream using C#

接收和播放: 使用 C# 从流中播放音频

The method of transport in between is up to you but if you already have a way of sending a stream between two computers you should be able to reuse that. Just make sure your buffer is big enough that there is always data to play back on the receiving computer.

两者之间的传输方法取决于您,但如果您已经有一种在两台计算机之间发送流的方法,您应该能够重用它。只要确保您的缓冲区足够大,以便始终有数据可以在接收计算机上播放。