Quantcast
Channel: NAudio
Viewing all articles
Browse latest Browse all 5831

New Post: streaming real time audio from bluetooth stethoscope

$
0
0
I got it! Still couldn't get it to work without threading, but it works like a charm like this. Now, I have to get it to stream over the network good enough so that there won't be noticeable lag as far away as India...
    NAudio.Wave.WaveFormat frm = new NAudio.Wave.WaveFormat(2000, 16, 2);
    BufferedWaveProvider bwProvider;
    WaveOut waveOut;

    public void Stream()
    {
        byte[] packet = new byte[128];
        int offSet = 0;
        int receivedPackets = 0;
        byte[] stethoscopeAudioData = new byte[128 * 5000];

        bwProvider = new BufferedWaveProvider(frm);
        bwProvider.BufferLength = (128 * 5000);

        new Thread(() =>
        {
            waveOut = new WaveOut();
            waveOut.Init(bwProvider);
            waveOut.Play();


        }).Start();

        stethoscope.StartAudioInput();

        while (receivedPackets < 5000)
        {
            int bytesRead = stethoscope.AudioInputStream.Read(packet, 0, packet.Length);

            if (bytesRead > 0)
            {
                // Data was bytesRead from the stream. Add the received packet to the audio data.
                Array.Copy(packet, 0, stethoscopeAudioData, offSet, bytesRead);
                bwProvider.AddSamples(stethoscopeAudioData, offSet, bytesRead);

                receivedPackets++;
                offSet += bytesRead;
            }
        }

        stethoscope.StopAudioInput();
    }

Viewing all articles
Browse latest Browse all 5831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>