Convert MP3 to WAV in Java

Retaining high levels of quality while working with large audio files necessitates the use of the WAV file format. This article will discuss how you can convert popular file formats like MP3 to WAV instantly using the following API.

Image for post
Image for post

First, we need to add a reference to the repository in pom.xml:


Then, we can add a reference for our API client to the dependency:


Now, we can call our function, AudioConvertToWav:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.AudioApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
AudioApi apiInstance = new AudioApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
String fileUrl = "fileUrl_example"; // String | Optional; URL of an audio file being used for conversion. Use this option for files larger than 2GB.
BigDecimal sampleRate = new BigDecimal(); // BigDecimal | Optional; Specify the desired sample rate of the converted audio file in kHz. Value may be between 8 and 96. Standard for audio CDs is 44.1, while DVD audio standard is 48. By default, the optimal sample rate will be chosen automatically.
try {
byte[] result = apiInstance.audioConvertToWav(inputFile, fileUrl, sampleRate);
} catch (ApiException e) {
System.err.println("Exception when calling AudioApi#audioConvertToWav");

With this, you can provide your applications with the capability to convert any audio file to WAV. To retrieve your free API Key, visit the Cloudmersive website. This will give you access to 800 monthly calls across our library of APIs.

Written by

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