Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cordova-plugin-media: Parse ".amr" Audio File on nodejs server

I'm using the cordova-plugin-media plugin to record audio-files from android and ios devices. However, android only allows to record the file in ".amr" ending, iOS on the otherside only supports ".wav". Playing the ".wav" from the iOS device on Android works, however, iOS doesn't support ".amr" files. That's why I have to convert them somehow.

Since I couldn't find any cordova-plugin converting the ".amr" file on the clientside besides this one (which is based on an external API and extreeeemly slow + not fully working - in addition that I'm not a fan of doing file-conversions on the client-side), I'm looking for a solution on the server-side:

Is there any javascript-library (best if it's "nodejs-friendly") allowing me to easily convert an ".amr" file to a ".wav" or ".mp3" (or similiar - just playable on iOS)? Despite ffmpeg (which I couldn't manage to install properly), I couldn't find ANY solutions... :(

(setting the mime-type to 'audio/wav' in the cordova-plugin-media creates a "corrupt" wav file, still amr-encode when analyzing it further with a tool...)

I really appreciate your help!

like image 420
nicost Avatar asked Nov 17 '15 12:11

nicost


1 Answers

I came up with a "solution", which I share with you if someone else is running in the same problems as I did:

www.cloudconvert.com offers a very simple api for "on-the-fly" converting video/audio/img files.

For node.js there is a node package for that I can recommend: https://github.com/cloudconvert/cloudconvert-node

I decided to convert the .amr to .mp3 and not .wav (iOS "standard") since .mp3 is smaller. To be able to play it on an iOS device though one has to adjust the bitrate a little bit from the (manual) example described on github. Make sure to pass the following options to your converting process:

  ccprocess.start({
    outputformat: 'mp3',
    input: 'download',
    file: 'path-to-your-file',
    converteroptions: {
      audio_bitrate: "721",
      audio_frequency: "44100",
      audio_qscale: -1
    }
  }, function (err, ccprocess) { ...
like image 123
nicost Avatar answered Oct 21 '22 23:10

nicost