Hi,
I am not very much experienced in audio programming but very much attracted with NAudio,Basically what i wanted to do is, capture the data (byte[]) from the microphone, then transport it over the network and play on client end. Just as voice call in chat application.
I tried saving the byte array in to the queue and send it to the service in certain interval.
long count = 0;
bool bufferfull = false;
private WaveIn waveIn = null;
private BufferedWaveProvider waveProvider = null;
private WaveOut waveOut = null;
private Queue<byte[]> datas = new Queue<byte[]>();
private void button1_Click(object sender, EventArgs e)
{
if (waveIn != null)
return;
waveIn = new WaveIn(this.Handle);
waveIn.BufferMilliseconds = 25;
waveIn.RecordingStopped += waveIn_RecordingStopped;
waveIn.DataAvailable += waveIn_DataAvailable;
waveProvider = new BufferedWaveProvider(waveIn.WaveFormat);
waveOut = new WaveOut();
waveOut.DesiredLatency = 100;
waveOut.Init(waveProvider);
waveOut.PlaybackStopped += wavePlayer_PlaybackStopped;
waveIn.StartRecording();
waveOut.Play();
}
void waveIn_DataAvailable(object sender, WaveInEventArgs e)
{
// add received data to waveProvider buffer
if (count <= 200)
{
if (waveProvider != null)
waveProvider.AddSamples(e.Buffer, 0, e.BytesRecorded);
}
if (count >= 200)
{
//send the byte array (Queue) as stream in to the network.
}
if (!bufferfull)
datas.Enqueue(e.Buffer);
count++;
}
and in the client side
datas = getTheQueueFromTheService();
while (datas.Count > 0)
{
var playingData = datas.Dequeue();
waveProvider.AddSamples(playingData, 0,playingData.Length);
Thread.Sleep(30);
waveOut.Play();
waveProvider.ClearBuffer();// because i got the exception Buffer full
}
but i found no luck. I googled for more the 3days, tried various methods still i was not able to figure out how to do it.
With the great hope for the assistance and help i have posted it here.I would be very greatful if some one could get me a piece of code.
and can i use NAudio to develop app as voice call provided by chat application.Is it appropriate.
Thank in advance.