Reputation: 2025
I am trying to record system audio.
Why this code returns exception. error message is BadDeviceId calling waveInOpen...
Is there something wrong in code ? Or should I make something out of code? I enabled microphone device on computer (from recording devices) but there is no microphone plugged in. I just want to record system audio.
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;
}
}
}
}
Upvotes: 2
Views: 6357
Reputation: 2025
solved.
I plugged in a microphone to computer and problem is solved. So the code works completely.
Upvotes: 2