Skip to main content
 首页 » 编程设计

c#之静音时 CSCore 环回录音

2024年02月06日66qq号

我正在使用 CSCore.WasapiLoopbackCapture 来录制系统声音。但是当系统没有声音的时候,根本就没有录音!例如,在播放音乐和录制音乐时,输出文件的持续时间小于轨道的持续时间。我希望它即使在系统中没有声音的情况下也能继续录制,但我没有找到任何属性来控制这种行为。这是我的代码片段:

WasapiCapture waveLoop = new WasapiLoopbackCapture(); 
waveLoop.Initialize(); 
waveLoop.DataAvailable += waveLoop_DataAvailable; 
waveLoop.Stopped += waveLoop_Stopped; 
waveLoop.Start(); 

请您参考如下方法:

对于您的“问题”,没有“好的”解决方案。但是您的问题已经得到描述here :

Another oddity is that WASAPI will only push data down to the render endpoint when there are active streams. When nothing is playing, there is nothing to capture.

这意味着您对这种行为无能为力。如果没有播放,则不会捕获任何内容。最简单的解决方案是:

But my particular favorite way of handling this is to run silence.exe. That way there are never any "nothing is playing" glitches, because there's always something playing.

因此,只需确保您的应用程序或任何其他应用程序静音即可。这将是一种确保您的应用程序记录静音而不是中断捕获的方法。