2

In my app I am recording voice using AudioRecorder as given in the following site, Audio Recorder it is working but it produce large size WAV file.

For example : If I record audio for 1 minute it takes 4MB to 5MB. So that I want to convert the wave file into MP3 file to reduce the size of the file. Please help me to compress the wav file ,give some example. Thanks in advance.

Ramil Aliyev 007
  • 4,437
  • 2
  • 31
  • 47

1 Answers1

-1

I never tried converting files before so i looked up on some threads that might be helpful to you.

One is converting wav to mp3 which require file conversion into a byte[]

public byte[] ConvertToMp3(Uri uri)
{
   using (var client = new WebClient())
   {
      var file = client.DownloadData(uri);
      var target = new WaveFormat(8000, 16, 1);
      using (var outPutStream = new MemoryStream())
      using (var waveStream = new WaveFileReader(new MemoryStream(file)))
      using (var conversionStream = new WaveFormatConversionStream(target, waveStream))
      using (var writer = new LameMP3FileWriter(outPutStream, conversionStream.WaveFormat, 32, null))
      {
         conversionStream.CopyTo(writer);

         return outPutStream.ToArray();
      }
   }
}

however on this method he is using a third party service which downloads the wav file and then to be called on that method but this does not guaranty if the file size will be reduced.

however i have check that you can compress wav files using a library called zlib. just decompress it whenever u need it.

Please check the link below: How to convert wav file to mp3 in memory?

Reducing WAV sound file size, without losing quality

psy
  • 48
  • 5
  • 1
    Thanks for you, Yeah, I download it, and I found I cannot use the using NAudio.Wave or using NAudio.Lame like the example codes in unity engine. Do you know how to fix it? I have no ideas. Could you help me? – Minshad 1213 Feb 11 '21 at 10:55