How to convert audio wav file to Mp3 file Xamarin forms

Viewed 604

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.

1 Answers

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

Related