Documentation menu

Guides

Audio

Compress audio to AAC, MP3, Opus or a lossless format, with control over bitrate, channels and sample rate.

Basic request

Send the audio file as the body of POST /v1/compress. Without options the output is AAC at 192 kbit/s in an .m4a file. This example makes a mono MP3 at 96 kbit/s, a common setting for speech:

curl -X POST "https://api.smolmac.com/v1/compress?audio.format=mp3&audio.quality=low&audio.channels=mono" \
  -H "Authorization: Bearer $SMOL_API_KEY" \
  --data-binary @interview.wav \
  -o interview.mp3

The result object reports the length of the audio in duration_seconds, which is what the price is based on.

Formats

Input can be MP3, AAC, WAV, FLAC, M4A, OGG, Opus or WMA. audio.format chooses the output:

audio.formatCodecFileLossy?
aac (default) or m4aAAC.m4aYes
mp3MP3.mp3Yes
oggOpus.oggYes
opusOpus.opusYes
wav16-bit PCM.wavNo
flacFLAC.flacNo
alacApple Lossless.m4aNo
originalThe codec family of the inputSee belowDepends

ogg and opus both produce Opus audio. They differ only in the file extension.

With original, an MP3 stays MP3, OGG and Opus stay Opus, and WAV and FLAC stay as they are. Any other input, including AAC, M4A and WMA, becomes AAC in an .m4a file.

The lossless formats are useful for changing container, not for saving space: a WAV written as FLAC is roughly half the size with no loss, while a lossy file written as WAV or FLAC gets larger and gains nothing.

Quality tiers and bitrates

audio.quality picks a bitrate for the lossy formats. The tiers are the same for AAC, MP3 and Opus.

audio.qualityBitrateTypical use
tiny64 kbit/sSpeech where size matters most
low96 kbit/sSpeech, podcasts in mono
balanced128 kbit/sPodcasts, background music
high (default)192 kbit/sMusic
maximum320 kbit/sMusic, when the file will be re-encoded later

To set a bitrate that is not one of the tiers, send audio.bitrate_kbps, a whole number from 16 to 512. It overrides audio.quality:

bash
curl -X POST "https://api.smolmac.com/v1/compress?audio.format=opus&audio.bitrate_kbps=48&audio.channels=mono" \
  -H "Authorization: Bearer $SMOL_API_KEY" \
  --data-binary @voicemail.wav \
  -o voicemail.opus

The lossless formats take no bitrate. For WAV, FLAC and ALAC, audio.quality and audio.bitrate_kbps are ignored.

Channels

audio.channelsResult
monoAll channels are mixed down to one.
stereo (default)The channels of the input are kept.
originalThe channels of the input are kept.

Only mono changes the channel count. stereo does not turn a mono recording into stereo, and it does not reduce surround audio to two channels.

The bitrate is for the whole file, not per channel. A mono file at 96 kbit/s has the same size as a stereo file at 96 kbit/s and sounds better, because all the bits go to one channel. For speech, mono at a lower tier is usually the best saving.

Sample rate

By default the output keeps the sample rate of the input. To change it, send audio.sample_rate_hz, a whole number from 8000 to 192000. Each output codec accepts a different range:

OutputAccepted sample rates
Opus (ogg, opus)8000, 12000, 16000, 24000 or 48000 only
MP3Up to 48000
AAC (aac, m4a)Up to 96000
WAV, FLAC, ALACAny value from 8000 to 192000

A rate outside the range for the chosen format fails with invalid_options. This is checked once the file has been read, so param is null and the message names the option.

Tags and cover art

Tags such as title, artist and album are kept by default. This is the opposite of images, where metadata is removed by default. To remove the tags, send audio.strip_metadata=true.

Embedded cover art is not carried into the output, whatever this option is set to.

When the original is kept

If the output has the same file type as the input and is not smaller, the API returns the input with Smol-Kept-Original: true, and the request is free. This is what happens when an MP3 at 128 kbit/s is sent with audio.format=mp3&audio.quality=high: encoding it again at a higher bitrate would only make it larger.

If the file type changes, you get the new file even when it is larger, and the result has increased: true. See Kept original.

Limits

  • A direct request takes a file of up to 25 MB and must finish within two minutes. Longer recordings go through a job. See Large files and jobs.
  • The length of a recording is limited by plan: 10 minutes on pay as you go, 60 minutes on Starter, and 3 hours on Growth, Scale and Enterprise. Longer audio fails with 422 limit_exceeded.
  • A file with no audio track fails with 422 processing_failed.

To change format with fixed settings and no options, there is also POST /v1/convert?to=mp3. See Convert files.

Billing

Audio costs $0.005 per started minute, for compression and for conversion. The length is the one reported in duration_seconds.

LengthStarted minutesPrice
20 seconds1$0.005
1 minute exactly1$0.005
1 minute 1 second2$0.010
45 minutes45$0.225

The price does not depend on the format, the bitrate or the size of the file. Failed requests and requests where the original was kept are free. See Billing.