gpt4 book ai didi

c# - NAudio WasapiLoopbackCapture ComException(0x88890003)

转载 作者:行者123 更新时间:2023-12-02 22:57:07 35 4
gpt4 key购买 nike

我正在尝试使用WasapiLoopbackCapture类(NAudio 1.7.1.17),并以COMException(0x88890003)结尾。记录格式为WaveFormat(44100, 16, 2)。我的系统上有多个播放设备,并尝试将每个播放设备设置为默认设备,结果相同。我还验证了每个设备都将(44100, 16, 2)列为受支持的格式。

控制台输出:

WasapiCapture_RecordingStopped.

Exception: System.Runtime.InteropServices.COMException (0x88890003): Exception from HRESULT: 0x88890003
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at NAudio.CoreAudioApi.AudioClient.get_AudioCaptureClient()
at NAudio.CoreAudioApi.WasapiCapture.DoRecording(AudioClient client)
at NAudio.CoreAudioApi.WasapiCapture.CaptureThread(AudioClient client)

代码:
public static class Program
{
private static int Index = 0;
private static int TotalBytesRecorded = 0;
private static bool RecordingStopped = false;

private static void Main (string [] args)
{
var device = NAudio.Wave.WasapiLoopbackCapture.GetDefaultLoopbackCaptureDevice();

using (var capture = new NAudio.CoreAudioApi.WasapiCapture(device))
{
capture.WaveFormat = new NAudio.Wave.WaveFormat(44100, 16, 2);
capture.ShareMode = NAudio.CoreAudioApi.AudioClientShareMode.Shared;
capture.DataAvailable += new EventHandler<NAudio.Wave.WaveInEventArgs>(Program.WasapiCapture_DataAvailable);
capture.RecordingStopped += new EventHandler<NAudio.Wave.StoppedEventArgs>(Program.WasapiCapture_RecordingStopped);

Program.Index = 0;
Program.TotalBytesRecorded = 0;
Program.RecordingStopped = false;

capture.StartRecording();
Thread.Sleep(TimeSpan.FromSeconds(10));
capture.StopRecording();

while (!Program.RecordingStopped)
{
Thread.Sleep(TimeSpan.FromMilliseconds(10));
}
}

Console.WriteLine();
Console.WriteLine();
Console.Write("TotalBytesRecorded: {0}.", Program.TotalBytesRecorded.ToString("N0"));
}

private static void WasapiCapture_DataAvailable (object sender, NAudio.Wave.WaveInEventArgs e)
{
Program.Index++;
Program.TotalBytesRecorded += e.BytesRecorded;

Console.WriteLine();
Console.Write
(
"Index: {0}, BytesRecorded: {1}, Buffer Length: {2}, TotalBytesRecorded: {3}.",
Program.Index.ToString("N0").PadLeft(10, ' '),
e.BytesRecorded.ToString("N0").PadLeft(10, ' '),
e.Buffer.Length.ToString("N0").PadLeft(10, ' '),
Program.TotalBytesRecorded.ToString("N0").PadLeft(10, ' ')
);
}

private static void WasapiCapture_RecordingStopped (object sender, NAudio.Wave.StoppedEventArgs e)
{
Program.RecordingStopped = true;

Console.WriteLine();
Console.WriteLine();
Console.Write("WasapiCapture_RecordingStopped.");

if (e.Exception != null)
{
Console.WriteLine();
Console.WriteLine();
Console.Write("Exception: {0}", e.Exception);
}
}
}

任何提示将不胜感激。

最佳答案

您不能为WASAPI回送捕获设置捕获-必须使用系统混合格式,该格式将使用32位浮点样本。只需直接使用WasapiLoopbackCapture类,它将起作用。

关于c# - NAudio WasapiLoopbackCapture ComException(0x88890003),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24566152/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com