Convert Audio to WAV format in PHP
While it’s easy to convert individual audio files to common formats like WAV, converting at scale presents a challenge which can easily result in an inefficient workflow. Thankfully, our “Convert Audio to WAV” API is free-to-use and accepts a wide range of input audio formats. To implement this API for free, all you need to do is follow steps below to structure your API call with ready-to-run PHP code examples, and then register a free account on our website to get your free-tier API key (which allows a limit of 800 API calls per month with no additional commitments).
First things first, let’s install the SDK by running the following command:
composer require cloudmersive/cloudmersive_video_api_client
Now let’s implement the following code examples & configure our inputs:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\AudioApi(
new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/inputfile"; // \SplFileObject | Input file to perform the operation on.
$file_url = "file_url_example"; // string | Optional; URL of an audio file being used for conversion. Use this option for files larger than 2GB.
$sample_rate = 8.14; // float | 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 {
$result = $apiInstance->audioConvertToWav($input_file, $file_url, $sample_rate);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling AudioApi->audioConvertToWav: ', $e->getMessage(), PHP_EOL;
}
?>
That’s all there is to it! Each request will return the encoding for a new WAV format file.