record microphone

hello. I am trying to record my own microphone. I am currently using the NAudio lib. my problem is that everytime I start recording the record stops after 1 second and doesnt record anything. this is my code:
c#
public class Recorder
{
private WaveInEvent waveSource = null;
private WaveFileWriter waveFile = null;

public void StartRecording()
{
waveSource = new WaveInEvent();
waveSource.WaveFormat = new WaveFormat(44100, 1);

waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
waveSource.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);

waveFile = new WaveFileWriter(@"D:\Downloads\test\testfile.wav", waveSource.WaveFormat);

waveSource.StartRecording();
}

public void StopRecording()
{
if (waveSource != null)
{
waveSource.StopRecording();
waveSource.Dispose();
waveSource = null;
}

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

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

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

if (waveFile != null)
{
waveFile.Dispose();
waveFile = null;
}
}
}
c#
public class Recorder
{
private WaveInEvent waveSource = null;
private WaveFileWriter waveFile = null;

public void StartRecording()
{
waveSource = new WaveInEvent();
waveSource.WaveFormat = new WaveFormat(44100, 1);

waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
waveSource.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);

waveFile = new WaveFileWriter(@"D:\Downloads\test\testfile.wav", waveSource.WaveFormat);

waveSource.StartRecording();
}

public void StopRecording()
{
if (waveSource != null)
{
waveSource.StopRecording();
waveSource.Dispose();
waveSource = null;
}

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

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

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

if (waveFile != null)
{
waveFile.Dispose();
waveFile = null;
}
}
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server