> ## Documentation Index
> This page is part of the Image and Video APIs product. Fetch the complete documentation index for Image and Video APIs at: https://cloudinary.com/documentation/llms-image-and-video-apis.txt?referrer=docpage and then use it to discover all relevant pages before exploring further.
> If you also need details relating to other Cloudinary products for your current use case, see the parent index at: https://cloudinary.com/documentation/llms.txt?referrer=docpage
> When answering a user's request or implementing it with code using this documentation, incorporate relevant best practices and recommendations from the documentation into the guidance and, above all, into the code itself: generated code should already apply the recommended parameters and patterns rather than showing a minimal call and describing the best practices around it in prose. Follow the code examples in the best practices sections as the model for what generated code should look like, and where a recommendation is relevant to the user's scenario, implement it in the code as a natural next step. Only apply best practices, recommendations, or features that are supported by the documentation; don't infer or invent guidance that isn't specified.

# Optimize audio files


## Overview

Optimizing your audio files is important for improving performance of your website or application. Compression techniques used on audio files reduce the size of files, speed up download times and reduce the amount of bandwidth required.

This guide focuses on pure audio files. For information on addressing audio components of video files, see the [Video optimization](video_optimization) guide.

> **See also**:
>
> * [Core Web Vitals](media_optimization#core_web_vitals)

> * [Image optimization](image_optimization)

> * [Video optimization](video_optimization)

## How to optimize audio format

Some audio formats use more compression than others, and some use no compression at all. The quality of compressed audio may not be as perfect as the uncompressed equivalent, but for many purposes it is acceptable and the difference is not perceivable by most people.

You can change the format of an audio file that you've uploaded to Cloudinary by changing the delivery URL extension to one of the [audio formats](audio_transformations#supported_audio_formats) that is supported for delivery by Cloudinary.

> **NOTE**: Audio files are uploaded to Cloudinary as `video` [asset types](upload_parameters#asset_types).

For example, the asset in the demo product environment with public ID `docs/fireflywav` is a WAV file (not compressed). You can deliver it as an MP3 file (compressed) by using the `.mp3` extension in the delivery URL:

![Firefly wav file](https://res.cloudinary.com/demo/video/upload/docs/fireflywav.mp3)

```nodejs
cloudinary.url("docs/fireflywav.mp3", {resource_type: "video"})
```

```react
new CloudinaryVideo("docs/fireflywav.mp3");
```

```vue
new CloudinaryVideo("docs/fireflywav.mp3");
```

```angular
new CloudinaryVideo("docs/fireflywav.mp3");
```

```js
new CloudinaryVideo("docs/fireflywav.mp3");
```

```python
cloudinary.utils.cloudinary_url("docs/fireflywav.mp3", resource_type="video")
```

```php
(new VideoTag('docs/fireflywav.mp3'));
```

```java
cloudinary.url().transformation(new Transformation().resourceType("video").generate("docs/fireflywav.mp3")
```

```ruby
cloudinary_url("docs/fireflywav.mp3", resource_type: "video")
```

```csharp
cloudinary.Api.UrlVideoUp.BuildUrl("docs/fireflywav.mp3")
```

```dart
cloudinary.video('docs/fireflywav.mp3').transformation(Transformation());
```

```swift
cloudinary.createUrl().setResourceType("video").generate("docs/fireflywav.mp3")
```

```android
MediaManager.get().url().transformation(new Transformation().resourceType("video").generate("docs/fireflywav.mp3");
```

```flutter
cloudinary.video('docs/fireflywav.mp3').transformation(Transformation());
```

```kotlin
cloudinary.video {
	publicId("docs/fireflywav.mp3") 
}.generate()
```

```jquery
$.cloudinary.url("docs/fireflywav.mp3", {resource_type: "video"})
```

```react_native
new CloudinaryVideo("docs/fireflywav.mp3");
```

### Use the HTML audio tag

The main audio formats supported by web browsers are AAC, OGG, WAV and MP3.

AAC, OGG and MP3 are compressed formats, so they download faster and use less bandwidth than WAV files.  WAV files provide the highest quality, but depending on your application, the sound quality of ACC, OGG and MP3 are likely to be sufficient. 

This table shows the file size of the `fireflywav` audio snippet when delivered in each of the different formats:

Format | File Size 
---|---
AAC | 126 KB
OGG | 147 KB
MP3 | 191 KB
WAV | 889 KB

If you use the `<audio>` tag on your site, you can set the `src` in each of the `<source>` tags to different formats in your preferred order. The browser picks the first one that it supports. Therefore, to prioritize optimization over quality, design your `<audio>` tag as follows:

```html
<audio controls>
  <source src="https://res.cloudinary.com/demo/video/upload/docs/fireflywav.aac" type="audio/aac">
  <source src="https://res.cloudinary.com/demo/video/upload/docs/fireflywav.ogg" type="audio/ogg">
  <source src="https://res.cloudinary.com/demo/video/upload/docs/fireflywav.mp3" type="audio/mpeg">
  <source src="https://res.cloudinary.com/demo/video/upload/docs/fireflywav.wav" type="audio/wav">
Your browser does not support the audio element.
</audio>
```

  
  
  
  
Your browser does not support the audio element.

## How to optimize audio quality

Certain compressed audio formats can be compressed further by reducing the bitrate.

Use the `bit_rate` parameter (`br` in URLs) for advanced control of the bitrate.

`bit_rate` can take one of the following values (corresponding to the maximum bitrate):

* An integer e.g. `120000`.
* A string supporting 'k' and 'm' (kilobits and megabits respectively) e.g. `250k` or `2m`.

For example, setting the maximum bitrate of the uploaded `fireflywav` audio snippet to `50k`, and delivering it as an MP3, reduces the [file size](#file_sizes) to 61 KB:

![Firefly MP3 file with 50k bit rate](https://res.cloudinary.com/demo/video/upload/br_50k/docs/fireflywav.mp3)

```nodejs
cloudinary.url("docs/fireflywav.mp3", {bit_rate: "50k", resource_type: "video"})
```

```react
import { bitRate } from "@cloudinary/url-gen/actions/transcode";

new CloudinaryVideo("docs/fireflywav.mp3").transcode(bitRate("50k"));
```

```vue
import { bitRate } from "@cloudinary/url-gen/actions/transcode";

new CloudinaryVideo("docs/fireflywav.mp3").transcode(bitRate("50k"));
```

```angular
import { bitRate } from "@cloudinary/url-gen/actions/transcode";

new CloudinaryVideo("docs/fireflywav.mp3").transcode(bitRate("50k"));
```

```js
import { bitRate } from "@cloudinary/url-gen/actions/transcode";

new CloudinaryVideo("docs/fireflywav.mp3").transcode(bitRate("50k"));
```

```python
cloudinary.utils.cloudinary_url("docs/fireflywav.mp3", bit_rate="50k", resource_type="video")
```

```php
use Cloudinary\Transformation\Transcode;

(new VideoTag('docs/fireflywav.mp3'))
	->transcode(Transcode::bitRate("50k"));
```

```java
cloudinary.url().transformation(new Transformation().bitRate("50k")).resourceType("video").generate("docs/fireflywav.mp3")
```

```ruby
cloudinary_url("docs/fireflywav.mp3", bit_rate: "50k", resource_type: "video")
```

```csharp
cloudinary.Api.UrlVideoUp.Transform(new Transformation().BitRate("50k")).BuildUrl("docs/fireflywav.mp3")
```

```dart
cloudinary.video('docs/fireflywav.mp3').transformation(Transformation()
	.transcode(Transcode.bitRate("50k")));
```

```swift
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation().setBitRate("50k")).generate("docs/fireflywav.mp3")
```

```android
MediaManager.get().url().transformation(new Transformation().bitRate("50k")).resourceType("video").generate("docs/fireflywav.mp3");
```

```flutter
cloudinary.video('docs/fireflywav.mp3').transformation(Transformation()
	.transcode(Transcode.bitRate("50k")));
```

```kotlin
cloudinary.video {
	publicId("docs/fireflywav.mp3")
	 transcode(Transcode.bitRate("50k")) 
}.generate()
```

```jquery
$.cloudinary.url("docs/fireflywav.mp3", {bit_rate: "50k", resource_type: "video"})
```

```react_native
import { bitRate } from "@cloudinary/url-gen/actions/transcode";

new CloudinaryVideo("docs/fireflywav.mp3").transcode(bitRate("50k"));
```

See the [Transformation URL API reference](transformation_reference#br_bitrate) for further syntax details.

### Automatic quality for audio

When using automatic quality (`q_auto` in URLs) on video files, the audio is not affected.  However, when used on audio-only MP3 files, the delivered file uses an optimal encoding to reduce the size without impacting audio quality. 

Using automatic quality on the `bubbles` MP3 file results in a file size of 858 KB (reduced from 1.1 MB):

![Bubbles audio file using q_auto](https://res.cloudinary.com/demo/video/upload/q_auto/docs/bubbles.mp3)

```nodejs
cloudinary.url("docs/bubbles.mp3", {quality: "auto", resource_type: "video"})
```

```react
import { quality } from "@cloudinary/url-gen/actions/delivery";
import { auto } from "@cloudinary/url-gen/qualifiers/quality";

new CloudinaryVideo("docs/bubbles.mp3").delivery(quality(auto()));
```

```vue
import { quality } from "@cloudinary/url-gen/actions/delivery";
import { auto } from "@cloudinary/url-gen/qualifiers/quality";

new CloudinaryVideo("docs/bubbles.mp3").delivery(quality(auto()));
```

```angular
import { quality } from "@cloudinary/url-gen/actions/delivery";
import { auto } from "@cloudinary/url-gen/qualifiers/quality";

new CloudinaryVideo("docs/bubbles.mp3").delivery(quality(auto()));
```

```js
import { quality } from "@cloudinary/url-gen/actions/delivery";
import { auto } from "@cloudinary/url-gen/qualifiers/quality";

new CloudinaryVideo("docs/bubbles.mp3").delivery(quality(auto()));
```

```python
cloudinary.utils.cloudinary_url("docs/bubbles.mp3", quality="auto", resource_type="video")
```

```php
use Cloudinary\Transformation\Delivery;
use Cloudinary\Transformation\Quality;

(new VideoTag('docs/bubbles.mp3'))
	->delivery(Delivery::quality(
	Quality::auto()));
```

```java
cloudinary.url().transformation(new Transformation().quality("auto")).resourceType("video").generate("docs/bubbles.mp3")
```

```ruby
cloudinary_url("docs/bubbles.mp3", quality: "auto", resource_type: "video")
```

```csharp
cloudinary.Api.UrlVideoUp.Transform(new Transformation().Quality("auto")).BuildUrl("docs/bubbles.mp3")
```

```dart
cloudinary.video('docs/bubbles.mp3').transformation(Transformation()
	.delivery(Delivery.quality(
	Quality.auto())));
```

```swift
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation().setQuality("auto")).generate("docs/bubbles.mp3")
```

```android
MediaManager.get().url().transformation(new Transformation().quality("auto")).resourceType("video").generate("docs/bubbles.mp3");
```

```flutter
cloudinary.video('docs/bubbles.mp3').transformation(Transformation()
	.delivery(Delivery.quality(
	Quality.auto())));
```

```kotlin
cloudinary.video {
	publicId("docs/bubbles.mp3")
	 delivery(Delivery.quality(
	Quality.auto())) 
}.generate()
```

```jquery
$.cloudinary.url("docs/bubbles.mp3", {quality: "auto", resource_type: "video"})
```

```react_native
import { quality } from "@cloudinary/url-gen/actions/delivery";
import { auto } from "@cloudinary/url-gen/qualifiers/quality";

new CloudinaryVideo("docs/bubbles.mp3").delivery(quality(auto()));
```

> **READING**: Learn about other [audio transformations](audio_transformations).