问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/23933906/how-to-record-audio-from-microphone-line-in-and-playback-device-speakers-line