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

New Post: WaveIn to SoundPlayer issue.

$
0
0

Hello,

I'm trying to use NAudio to capture mic sound and be able to play it in SoundPlayer class. Sound player expects a memory stream with a wav file in it. This is the function using SoundPlayer:

 

 public static void PlaySoundByteData(byte[] data)
        {
            try
            {
                using (Stream s = new MemoryStream(data))
                {
                    // http://msdn.microsoft.com/en-us/library/ms143770%28v=VS.100%29.aspx
                    SoundPlayer myPlayer = new SoundPlayer(s);
                    myPlayer.Play();
                }
            }
            catch
            {
                //Do Nothing
            }
        }
    }

Per VoiceRecorder example project in the site, I am using the WaveIn class buffer data (byte[]) to pass into the function above, but it throws an exception claiming corrupt headers. I don't want to save the buffer in the disk (at least just yet). I want to be able to use the function above as it is being globally for other sound wave streams. For reference I am using AudioRecorder class in the VoiceRecorder project without any changes (other than capturing the WaveIn buffer). Can anyone please suggest a way to achieve this. 


Viewing all articles
Browse latest Browse all 5831

Trending Articles



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