-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicModule.cs
More file actions
42 lines (35 loc) · 1.18 KB
/
MicModule.cs
File metadata and controls
42 lines (35 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using NAudio;
using NAudio.Wave;
public class MicModule
{
public MicModule()
{
// Specify the file name and format
string fileName = "tester.wav";
WaveFormat waveFormat = new WaveFormat(44100, 16, 2); // 44.1kHz, 16-bit, stereo
// Create a WaveIn instance for recording
using (WaveInEvent waveIn = new WaveInEvent())
{
// Set the desired WaveFormat
waveIn.WaveFormat = waveFormat;
// Set the callback for when data is recorded
waveIn.DataAvailable += (sender, e) =>
{
// Write the recorded data to a file
using (WaveFileWriter writer = new WaveFileWriter(fileName, waveIn.WaveFormat))
{
writer.Write(e.Buffer, 0, e.BytesRecorded);
writer.Flush();
}
};
// Start recording
waveIn.StartRecording();
// Wait for user input to stop recording
Console.WriteLine("Recording... Press Enter to stop.");
Console.ReadLine();
// Stop recording
waveIn.StopRecording();
}
}
}