Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NAudio Convert Byte Array to Wav

Tags:

c#

naudio

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.

like image 390
Blast Avatar asked Oct 04 '22 05:10

Blast


1 Answers

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);
}
like image 63
BartoszKP Avatar answered Oct 07 '22 19:10

BartoszKP