This project has moved. For the latest updates, please go here.

How to create a virtual audio source with NAudio?

Nov 3, 2012 at 5:07 PM

To create a virtual audio input source to use in Skype etc. by mixing Line in and some other wave file together. Like Virtual Audio Cable.

Coordinator
Nov 4, 2012 at 8:47 AM

Unfortunately you can't create Virtual Audio Cable with NAudio - you'd need to use the Windows Driver Kit and make it in C/C++.

However, if you want to feed audio ito Skype then you can look at the Skype4Com library which lets you do this (you open up a port and send audio to it).

Nov 4, 2012 at 12:34 PM

That's what I want to do.

"you open up a port and send audio to it"

Elaborate please.

Nov 4, 2012 at 4:21 PM
Edited Nov 4, 2012 at 4:26 PM

So I looked at http://channel9.msdn.com/coding4fun/articles/Skype-Voice-Changer. I started reading at Intercepting Skype Audio.

What I understand is that the most important part is

 void OnMicServerExecute(object sender, DataReceivedEventArgs args)
        {
            toolStripStatusLabel1.Text = "Got " + args.Buffer.Length + " bytes";
            if (outStream != null)
            {
                // give the input audio to the beginning of our audio graph
                bufferStream.SetLatestInBuffer(args.Buffer);
                // process it out through the effects
                outputStream.Read(args.Buffer, 0, args.Buffer.Length);
                // play it back
                outStream.Write(args.Buffer, 0, args.Buffer.Length);
            }
        }

So you set up a TCPServer you stream the mic-data from skype to. Then you replace the stream with your modified data and give it to outStream, which again is delivered to the other side. So outputStream has to contain my content somehow. This is where the problem comes in. I have my microphone connected with LINE-IN. I want the LINE-IN stream to be mixed with a sound file I am currently playing using

void abspielen(string Dateiname, float ZielAmplitude)
{
	Klangwiedergabegeraet = new WaveOutEvent();
	Klangwiedergabegeraet.DeviceNumber = cbAusgabegeraete.SelectedIndex;
	timer1.Enabled = true;
	ISampleProvider StueckchenHalter = null;
	try
	{
		StueckchenHalter = CreateInputStreamS(Dateiname,ZielAmplitude);
	}
	catch (Exception createException)
	{
		MessageBox.Show(String.Format("{0}", createException.Message), "Error Loading File");
			return;
	}
	try
	{
		Klangwiedergabegeraet.Init(new SampleToWaveProvider(StueckchenHalter));
	}
	catch (Exception initException)
	{
		MessageBox.Show(String.Format("{0}", initException.Message), "Error Initializing Output");
			return;
	}
	Klangwiedergabegeraet.Play();
}

and forwarded to Skype.

Please give me a route to accomplish this.