VGD
VGD

Reputation: 466

mix microphone with mp3 file and output that to specific device

I'd like to be able to mix the microphone output with a mp3-File, and output that to a specific device.

I got playing the mp3-File to a specific device working:

Mp3FileReader reader = new Mp3FileReader("C:\\Users\\Victor\\Music\\Musik\\Attack.mp3");
var waveOut = new WaveOut();// or WaveOutEvent()
waveOut.DeviceNumber = deviceId; //deviceId, like 0 or 1
waveOut.Init(reader);
waveOut.Play();

So would I would like to be able to do is basically send the microphone output always to specific output and overlay that output to that specific device with the sound of a mp3-file when for example a button is pressed. Now is what I'm trying to do possible with naudio and if so how would I go about it?

Thanks!

Upvotes: 0

Views: 763

Answers (1)

Mark Heath
Mark Heath

Reputation: 49482

The basic strategy is to put the audio rececived from the microphone into a BufferedWaveProvider. Then turn that into an ISampleProvider with the ToSampleProvider extension method. Now you can pass that into a MixingSampleProvider. Then play from the MixingSampleProvider. Now at any time you can mix in other audio by adding an input into the MixingSampleProvider

Upvotes: 1

Related Questions