Naudio BadDeviceId 在 C# 中调用 waveInOpen 错误

Naudio BadDeviceId calling waveInOpen Error in C#

我正在尝试录制系统音频。

为什么这段代码returns异常。错误消息是 BadDeviceId 调用 waveInOpen...

代码有问题吗?或者我应该用代码做点什么?我在电脑上启用了麦克风设备(来自录音设备),但没有插入麦克风。我只想录制系统音频。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NAudio;
using NAudio.Wave;


namespace SeleniumDeneme.Classes
{
    class RecorderForVideo
    {

        public WaveIn waveSource = null;
        public WaveFileWriter waveFile = null;


        public RecorderForVideo() { }

        public void CreateObjectsForRecord() 
        {
             waveSource = new WaveIn();
             waveSource.WaveFormat = new WaveFormat(44100, 1);
             waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
             waveSource.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);

             waveFile = new WaveFileWriter(@"C:\Users\BerkayS\Desktop\Test0001.wav", waveSource.WaveFormat);


             waveSource.StartRecording();


        }

        void waveSource_DataAvailable(object sender, WaveInEventArgs e)
        {
            if (waveFile != null)
            {
                waveFile.Write(e.Buffer, 0, e.BytesRecorded);
                waveFile.Flush();
            }
        }

        void waveSource_RecordingStopped(object sender, StoppedEventArgs e)
        {
            if (waveSource != null)
            {
                waveSource.Dispose();
                waveSource = null;
            }

            if (waveFile != null)
            {
                waveFile.Dispose();
                waveFile = null;
            }


        }



    }
}

已解决。

我在电脑上插了一个麦克风,问题就解决了。所以代码完全有效。