How to Convert Audio to MP3 in Node.JS

The process of media production and editing can be tedious one, and occasionally you may have greater use for a clip’s audio as an MP3, separate from any video or longer format sound. If you need to extract a sound bite for use by your organization, whether for promotional, educational, or other purposes, the following API can help you manage the process with ease, by converting audio files to MP3 using Node.JS.

Image for post
Image for post

First, we need to install our client:

npm install cloudmersive-video-api-client --save

Or, conversely, we may add the following piece to our package.json:

"dependencies": {
"cloudmersive-video-api-client": "^2.0.1"
}

Following this, we can call our function, AudioConvertToMp3:

var CloudmersiveVideoApiClient = require('cloudmersive-video-api-client'); var defaultClient = CloudmersiveVideoApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';

var apiInstance = new CloudmersiveVideoApiClient.AudioApi();
var opts = {
'inputFile': Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer), // File | Input file to perform the operation on.
'fileUrl': "fileUrl_example", // String | Optional; URL of an audio file being used for conversion. Use this option for files larger than 2GB.
'bitRate': 56 // Number | Optional; Specify the desired bitrate of the converted audio file in kilobytes per second (kB/s). Value may be between 48 and 1,411. By default, the optimal bitrate will be chosen automatically.
};
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.audioConvertToMp3(opts, callback);

And with that, you can quickly and easily convert any audio into MP3 to collect exactly what you need!

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store