0
votes

I would like to know if it is possible to convert mp3 to wave using nAudio library but without saving converted file to disc (using for example MemoeryStream) ?

Link to nAudio

Any examples?

I tried like this:

byte[] fileStream = null;
MemoryStream ms2 = new MemoryStream();
using (WaveStream waveStream = WaveFormatConversionStream.CreatePcmStream(newMp3FileReader(filePath)))
using (WaveFileWriter waveFileWriter = new WaveFileWriter(ms2,waveStream.WaveFormat))
                    {
                        byte[] bytes3 = new byte[waveStream.Length];
                        waveStream.Position = 0;
                        waveStream.Read(bytes3, 0, (int)waveStream.Length);
                        waveFileWriter.Write(bytes3, 0, bytes3.Length);
                        fileStream = bytes3;
                        return fileStream;
                    } 

When I saved file from byte array it is damaged. Screen:

Screen

1
Your bytes3 just contains PCM, not a WAV file. You need to get the underlying byte array from the memory stream AFTER disposing the WaveFileWriter.Mark Heath
Thanks, it's working.Toystoj

1 Answers

0
votes

The simplest way to do it is to pass a MemoryStream instance to WaveFileWriter constructor, then write all the samples to the writer... For the decoding side you can use the Mp3FileReader...

Good luck!