Convert byte array to wav file

Eyla picture Eyla · Apr 19, 2010 · Viewed 27.3k times · Source

I'm trying to play a wav sound that stored in byte array called bytes. I know that I should convert the byte array to wav file and save it in my local drive then called the saved file but I was not able to convert the byte array to wav file.

please help me to give sample code to convert byte arrary of wav sound to wav file.

here is my code:

protected void Button1_Click(object sender, EventArgs e)
{
    byte[] bytes = GetbyteArray();

   //missing code to convert the byte array to wav file

    .....................

    System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer(myfile);
    myPlayer.Stream = new MemoryStream();
    myPlayer.Play();
}

Answer

Jay Riggs picture Jay Riggs · Apr 19, 2010

Try this:

System.IO.File.WriteAllBytes("yourfilepath.wav", bytes);