Darxis
Darxis

Reputation: 1570

How to record audio from microphone (Line-In) and playback device (speakers Line-Out) to one MP3 file

I am trying to record audio from the microphone and speakers to one MP3 file.

How to achieve this in C# with NAudio?

I have already recorded audio from microphone, but I can't figure out how to record from speakers, and then mix to one MP3 file.

Upvotes: 1

Views: 3096

Answers (1)

Mark Heath
Mark Heath

Reputation: 49482

You'd need to record the microphone and the speakers separately, then mix them, then convert to MP3.

To record the speakers, you should look at WasapiLoopbackCapture. One caveat is that WASAPI Loopback Capture doesn't always return data if nothing is playing, so you can work around this by playing silence while you are recording.

To record the microphone you could use WasapiCapture. Then having captured both as WAV, you can use a MixingSampleProvider followed by a WaveFileWriter to mix them down to WAV, and then maybe use the MediaFoundationEncoder to make MP3, or more use LAME.exe if you don't have a media foundation MP3 encoder installed.

Upvotes: 2

Related Questions