我正在尝试录制系统音频。
为什么此代码返回异常。错误信息是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;
}
}
}
}
答案 0 :(得分:1)
解决。
我将麦克风插入电脑,问题解决了。所以代码完全可以运行。