Convert byte array to wav file

后端 未结 3 2100
栀梦
栀梦 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:02

    Using NAudio and you can try something like:

    //var wavReader = new WaveFileReader(yourWavFilePath);
    //byte[] buffer = new byte[2 * wav1Reader.WaveFormat.SampleRate * wav1Reader.WaveFormat.Channels];
    byte[] buffer = YourWaveSoundByteArray;
    
    using ( WaveFileWriter writer = new WaveFileWriter(YourOutputFilePath, new WaveFormat( AssignWaveFormatYouWant /*wavReader.WaveFormat.SampleRate, 16, 2/*how many channel*/))
        )
    {
        //int bytesRead;
        //while ((bytesRead = wavReader.Read(buffer, 0, buffer.Length)) > 0)
        //{
            writer.Write(buffer, 0,  buffer.Length/*bytesRead*/);
        //}
    }
    

提交回复
热议问题