Этот код сгенерирует файл wav, но не содержит записи.
// Определение выходного файла wav записанной звуковой строки outputFilePath = @ "C: \ Users \ system_recorded_audio.wav";
// Redefine the capturer instance with a new instance of the LoopbackCapture class
WasapiCapture CaptureInstance = new WasapiLoopbackCapture();
// Redefine the audio writer instance with the given configuration
WaveFileWriter RecordedAudioWriter = new WaveFileWriter(outputFilePath, CaptureInstance.WaveFormat);
// When the capturer receives audio, start writing the buffer into the mentioned file
CaptureInstance.DataAvailable += (s, a) =>
{
DelaySeconds(5);
// Write buffer into the file of the writer instance
RecordedAudioWriter.Write(a.Buffer, 0, a.BytesRecorded);
};
DelaySeconds(5);
// When the Capturer Stops, dispose instances of the capturer and writer
CaptureInstance.RecordingStopped += (s, a) =>
{
RecordedAudioWriter.Dispose();
RecordedAudioWriter = null;
CaptureInstance.Dispose();
};
// Start audio recording !
CaptureInstance.StartRecording();
}
public static void DelaySeconds(int iTimeSec)
{
TimeSpan delay = TimeSpan.FromSeconds(iTimeSec);
DateTime start = DateTime.Now;
TimeSpan elapsed = TimeSpan.Zero;
// waits in a while loop while checking the abort or cancel flag
while (elapsed < delay)
{
Thread.Sleep(10);
elapsed = DateTime.Now - start;
}
}