Drupal: Media Recorder Module And Audio Conversion With FFMPEG

Media recorder Module and Audio Conversion

Audio conversion with Media recorder and audio converter using FFMPEG

We have faced a problem with browser's version support while delivering our one of the esteem project "Lingora" - we worked recently and thought to share with you people to save your precious time with Audio conversation functionality. Digging out for its solution really hacks our minds sometimes.

But now relax!! Here's the quick solution we imposed to save your time and guess what!! That works very well.

We used media recorder module to record the audios from a browser. Some of the important things to be considered while using this module:

  • Different browsers record audios with different formats.
  • iOS doesn't allow recording audios.
  • Chrome requires to enable extension and needs https.

Different browsers record audios with different formats:

Different browsers record audios in a different format. For example, Firefox on Ubuntu saves a file as .ogg. , chrome makes .wav files. These formats are not cross-browser compatible and not all audio formats can be played on all browsers.

To solve different formats issue, we used an audio-converter module. This module converts uploaded audios to .mp3. This module works well with an audio field. Since we are using media recorder, we used a patch from here to make it work for the audio recorder.

Along with this we also added a patch to make it work in file field as well. https://www.drupal.org/node/2687469

We still had an issue in firefox that it did not play .mp3 files. So we converted .mp3 files into .ogg and kept two files for one content.

We used FFMPEG in custom code to make conversion using following code:

exec('ffmpeg -i '.$source_file.' -acodec libvorbis '.$new_file_name.'.ogg');

iOS doesn’t allow to record audios

iOS doesn't support audio recording. Instead, we are given an option to upload a file. In file upload also, we can either take a photo or video or we can upload one from the gallery.

iOS doesn't allow to upload audio files. You can only access the gallery. The workaround here is to record a video from iOS devices and then convert it to an audio file using audio converter.

The audio converter works here as well and converts the recorded/uploaded video in mp3 file.

Chrome requires to enable extension and needs https

According to this, chrome 47 onwards to use media recorder you need to enable one flag and the site needs to be on https.

Hope this solution helped you, use this solution Blindly! Leave your valuable feedbacks, would get back to the easiest solution for complex tasks.