Search code examples
c#bytewavsoundplayer

send array of bytes to System.Media.SoundPlayer in c#


I want send string byte to speaker something like this:

byte[] bt = {12,32,43,74,23,53,24,54,234,253,153};// example array
var ms = new MemoryStream(bt);
var sound = new System.Media.SoundPlayer();
sound.Stream = ms;
sound.Play();

but I get this exception: my problem pic http://8pic.ir/images/g699b52xe5ap9s8yf0pz.jpg


Solution

  • You can use some library for reading data from microphone or playing it to speakers. I worked successfuly with: NAudio - http://naudio.codeplex.com/

    I would not recommend building a WAV file yourself, it may be too much effort for this. Note that this library (and probably some others, Bass - http://www.un4seen.com is also widely used) also have built in functionality for saving and reading WAV files.