Convert byte array to wav file

后端 未结 3 2045
栀梦
栀梦 2021-02-04 07:11

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 sav

3条回答
  •  终归单人心
    2021-02-04 08:05

    You can use something like File.WriteAllBytes(path, data) or...

    ...Alternatively if you don't want to write the file you could convert the byte array to a stream and then play that...

    var bytes = File.ReadAllBytes(@"C:\WINDOWS\Media\ding.wav"); // as sample
    
    using (Stream s = new MemoryStream(bytes))
    {
        // http://msdn.microsoft.com/en-us/library/ms143770%28v=VS.100%29.aspx
        System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer(s);
        myPlayer.Play();
    }
    

    PK :-)

提交回复
热议问题