Convert Audio to AAC Format in PHP
Looking for an easy way to convert your audio files to AAC format? You can easily take advantage of our “Convert Audio to AAC” API with the complementary, ready-to-run PHP Code examples provided below. The underlying service accepts a wide variety of input audio formats and returns the encoding for new AAC files.
To begin, install the SDK by running the following command:
composer require cloudmersive/cloudmersive_video_api_client
To structure your API call, copy from the following code examples. In order to authenticate your request, head to our website and grab a free-tier API key (you’ll need to register a free account; this will provide you with a limit of 800 API calls per month and zero additional commitments):
<?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.
$bit_rate = 56; // int | 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.
try {
$result = $apiInstance->audioConvertToAac($input_file, $file_url, $bit_rate);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling AudioApi->audioConvertToAac: ', $e->getMessage(), PHP_EOL;
}
?>
That’s all it takes — now you can convert to AAC with ease. Enjoy!