To convert .wav audio file to .mp3 in flutter

3.8k Views Asked by At

I have a feature to listen to audio files, I'm getting audio files in .wav format and takes too long to play audio. When i tried .mp3 file with same audio player its delay decreased.

Is there any way to convert .wav to .mp3 or any other approches?

 FFmpegKit.execute('-i $url output.mp3').then((session) async {
                                                        final returnCode = await session.getReturnCode();

                                                        if (ReturnCode.isSuccess(returnCode)) {
                                                     

                                                          // SUCCESS

                                                        } else if (ReturnCode.isCancel(returnCode)) {

                                                          // CANCEL

                                                        } else {
                                                       

                                                          // ERROR

                                                        }
                                                      })
1

There are 1 best solutions below

6
ezzou On

ffmpeg is a complete, cross-platform solution to record, convert and stream audio and video.

Here is a great package that ports ffmpeg features to flutter

Below is a usage example of the package that converts a input.wav file to an output.mp3 file:

import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart';

 FFmpegKit.execute('-i input.wav output.mp3').then((session) async {
   final returnCode = await session.getReturnCode();

   if (ReturnCode.isSuccess(returnCode)) {

     // SUCCESS

   } else if (ReturnCode.isCancel(returnCode)) {

     // CANCEL

   } else {

     // ERROR

   }
 });

You can easily convert between different file formats,

here is a link to the official ffmpeg website if you want to learn more