This project has moved and is read-only. For the latest updates, please go here.

byte array to WAV?

Feb 28, 2012 at 6:30 PM

Hi, i have a project that needs to convert an ASCII text file or a BIN file to a WAV file. I understand the formats of the files but my coding is not very strong.


I can read the ASCII file, that contains a series of floats. this then needs to be converted to a byte array where it can then be used to create a WAV file. I found the NAudio library and was wondering if this is possible in NAudio and if anyone can highlight techniques that could help me i would be very greatfull  


Feb 28, 2012 at 9:05 PM

Hi Mike,

The WaveFileWriter class has a WriteSample method you can call for each float in your input file


Feb 28, 2012 at 10:51 PM

Thanks for replying Mark.  do you know how this would be done? i am trying to use visual c#, using a GUI to open the ASCII .txt file then write the samples to wave format. I am not to clear on the processes it would take to do that from a txt or BIN file


Mar 2, 2012 at 1:38 PM

well to parse samples in a text file you would use float.Parse. For a binary file, you would need to use a FileStream and read into a buffer, and then use the BitConverter to get the data out as samples

Mar 9, 2012 at 5:04 PM


Thanks for your help. I am currently working to convert the binary file to wav. i am using the steps you recommended but the wav file sounds like noise with a high pitch. I am using ReadAllBytes to create a byte [] from the file. I have tried to use bit converter and the file sounds no different. Can you think of anything i am doing wrong in the conversion steps or anything else i should try. 


Mar 9, 2012 at 5:21 PM


Please ignore last post. The program I created using NAudio successfully converts bin files to the wav format. Does the WaveFileWriter always write at 44.1 or can this be changed? The next step I need to do is read ascii files, convert the data to byte array and then use it to create a wav file.


Mar 10, 2012 at 9:37 AM

The WaveFileWriter takes a WaveFormat object in its constructor. Just pass in one with a different sample rate.