我使用NAudio lib创建Windows服务,从声卡中捕获音频,抛出Wasapi。但在其中一台计算机上我得到hresult = -2147024809,当我调用audioClientInterface.Initialize 这是我用来捕获的代码。
public partial class TestRecorder : ServiceBase
{
private static readonly Logger _logger = LogManager.GetLogger("ServiceLogger");
public TestRecorder()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
ThreadPool.QueueUserWorkItem(x =>
{
using (var rec = new Recorder())
{
rec.Start();
Thread.Sleep(10000);
rec.Stop();
}
});
}
protected override void OnStop()
{
}
internal void TestStartupAndStop(string[] args)
{
this.OnStart(args);
Console.ReadLine();
this.OnStop();
}
}
Here is code of Recorder.
public class Recorder : IDisposable
{
private static readonly Logger _logger = LogManager.GetLogger("ServiceLogger");
private WasapiCapture MicroCapture { get; set; }
private WaveFileWriter Writer { get; set; }
public Recorder()
{
var deviceEnum = new MMDeviceEnumerator();
MMDevice micro = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Communications);
MicroCapture = new WasapiCapture(micro);
MicroCapture.DataAvailable += OnDataAvailible;
Writer = new WaveFileWriter(@"C:\Temp\test.wav", MicroCapture.WaveFormat);
_logger.Trace("Recorder is initialized");
}
private void OnDataAvailible(object sender, WaveInEventArgs e)
{
if (e.BytesRecorded > 0)
{
Writer.Write(e.Buffer, 0, e.BytesRecorded);
}
}
public void Start()
{
try
{
MicroCapture.StartRecording();
_logger.Trace("Recorder started");
}
catch (Exception ex)
{
_logger.Fatal(ex);
}
}
public void Stop()
{
try
{
MicroCapture.StopRecording();
_logger.Trace("Recorder stopped");
}
catch (Exception ex)
{
_logger.Fatal(ex);
}
}
public void Dispose()
{
MicroCapture.Dispose();
Writer.Dispose();
_logger.Trace("Capture and writer disposed");
}
}
尝试安装3种不同的驱动程序。
试图使用不同的格式。
NAudio发送下一个参数
audioClientInterface.Initialize发送下一个参数。
shareMode = Shared,
streamFlags = None,
bufferDuration = 1000000,
periodicity = 0,
waveFormat = 32 bit PCM: 48kHz 2 channels wBitsPerSample:32 dwChannelMask:3 subFormat:00000003-0000-0010-8000-00aa00389b71 extraSize:22,
audioSessionGuid = 00000000-0000-0000-0000-000000000000
在扬声器和麦克风设置中,我选择48000 hz 16 bit
。
请给我一些解决这个问题的提示,我该如何调试或解决这个问题。声卡模型为VIA vt1708s
,主板模型为Asus P8H61-M LX3 R2.0
IAudioClient :: IsFormatSupproted返回S_OK。
答案 0 :(得分:2)
我通过将我的Windows服务添加到Kaspersky Antivirus应用程序的例外来确定它并且它有效。