5
votes

I am using NAudio to capture an audio signal from my line in device into a byte array. I can successfully send that byte array across my WLAN via UDP broadcast and receive it on another computer. Once the byte array has been received, I am able to play the audio stream.

My goal is to stream an audio signal from a line in device so it can be consumed by an HTML5 audio tag or jPlayer. Do you have an example or reading material on how to convert the input byte array to stream as compatible HTML5 format?

I would to to create a .Net solution without using any third party applications.

Here is a sample of how I am capturing and broadcasting the audio signal via UDP.

var waveIn = new WaveInEvent();
waveIn.DeviceNumber = deviceID;
waveIn.WaveFormat = Program.WAVEFORMAT;
waveIn.BufferMilliseconds = 50;
waveIn.DataAvailable += OnDataAvailable;

var udpSender = new UdpClient();
udpSender.JoinMulticastGroup(Program.MulticastIP);

waveIn.StartRecording();

private void OnDataAvailable(object sender, WaveInEventArgs e)
{
    udpSender.Send(e.Buffer, e.BytesRecorded, Program.EndPoint);
}
1
Can you post details how you send and receive the signal? Or If you have example project please share with us. Thank you!xmlParser

1 Answers

0
votes

The answer to your question is really dependent on whether you want to stream the audio to a HTML5 compatible browser, or whether you simply want to playback recorded audio.

According to W3Schools, all major browsers support the major audio formats (wav/ogg/mp3):

http://www.w3schools.com/html/html5_audio.asp

Playing a pre-recorded audio file using the HTML5 audio tag is pretty easy. The link above describes how to accomplish that.

Live-streaming the audio to a HTML5 browser is a whole different story. You need some kind of streaming server. I would advise against trying to implement this yourself. It's much easier to just use an external library for this.

The only reliable solution I can think of right now is using one of the freely available .Net P/Invoke libraries for libvlc, which provides access to the streaming capabilities of the VLC Media Player.

The following StackOverflow question describes how to setup an audio streaming server using libvlc:

Use libvlc to stream mp3 to network

You can try to accomplish the same thing in C#. It might require some P/Invoke work, but it's the most realiable solution I can think of.