How to Convert Audio Input to Text in C/C++

Cloudmersive
1 min readAug 24, 2021

Did you know that machine learning can assist in making your websites and applications more accessible for the hearing impaired? In this brief tutorial, we will discuss how you can use an API solution in C/C++ that leverages advanced machine learning to automatically convert input MP3 or WAV files into text, allowing easy transcription of the audio.

Let’s start things off by installing libcurl into your C/C++ project:

libcurl/7.75.0

Next, you can call the speech recognition function with the following code:

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/speech/recognize/file");
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, "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, "speechFile");
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 text transcription will be ready in an instant, enabling a better experience for your customers and partners.

--

--

Cloudmersive

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