Here's a quick C # Console application that I wrote using NAudio, mic input, speaker output, encoded with U-Law or A-Law. The NAudio.Codecs namespace contains A-Law and u-Law encoders and decoders.
This program does not transmit data over the network (this is not difficult to do, I just did not want to do it here). I will leave it to you. Instead, it contains the Sender stream and the Receiver stream.
The DataAvailable microphone event DataAvailable simply drops the byte buffer into the queue (it makes a copy of the buffer β you don't want to keep the actual buffer from the event). The Sender stream captures buffer queues, converts PCM data to g.711, and transfers it to the second queue. This part βfalls into the second placeβ is the place where you send the remote UDP destination for your specific application.
The "Receiver" stream reads data from the second queue, converts it back to PCM and transfers it to the BufferedWaveProvider , which is used by the WaveOut device (speaker). You would replace this input with UDP socket reception for your network application.
Please note that the program ensures that the PCM input and output (microphone and speaker) use the same WaveFormat . This is what you will also need to do for network endpoints.
Anyway, it works. So here is the code. I will not go into details. There are many comments to try to understand what is going on:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using NAudio.Wave; using NAudio.Codecs; namespace G711MicStream { class Program { delegate byte EncoderMethod( short _raw ); delegate short DecoderMethod( byte _encoded );
Bob c source share