Convert MP3 to WAV in C/C++

WAV files are a great format to use when working with large audio files. They preserve the quality of the audio, and as long as you don’t have any worries about storage size or web-sharing, they can be ideal for audio and music software projects. So, if you have a large MP3 file you want to convert into the WAV format, the following API can be run in C/C++ to automate the otherwise time-consuming task for you.

To begin, we will need to install libcurl to the C/C++ project:

libcurl/7.75.0

Moving on, we are ready to call the conversion function; the only required parameter is your input file, but you have the option to add the file URL (recommended for files over 2 GB) or specify the desired sample rate in khZ (default is to allow the API to choose the rate automatically).

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/video/convert/to/wav");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "fileUrl: <string>");
headers = curl_slist_append(headers, "sampleRate: <number>");
headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile");
curl_mime_filedata(part, "/path/to/file");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
}
curl_easy_cleanup(curl);

The processing time may be longer or shorter based on the size of your file, but the wait time (and stress!) is significantly less than what it would take if you attempted the process manually.

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