5
votes

I looked into NAudio classes but couldn't see a class that converts byte array to WAV file. If there is no class like this, how can I convert byte array to WAV file using NAudio?

I want to send a text to RS232 as bytes, then I will get back those bytes into a byte[] buffer. After getting back data I want to save them as a WAV file using NAudio.

I tried to use WaveBuffer class but I think I am trying a wrong way.

1

1 Answers

4
votes

This blog post explains how to use the WaveFileWriter class for this purpose:

byte[] testSequence = new byte[] { 0x1, 0x2, 0xFF, 0xFE };
using (WaveFileWriter writer = new WaveFileWriter(fileName, waveFormat))
{
    writer.WriteData(testSequence, 0, testSequence.Length);
}