← Audio converter
Convert audio to MP3 in Python
Convert audio between MP3, OGG, Opus, M4A, WAV and FLAC. Trim it, make it mono, or change the sample rate. Here is the whole call in Python, with the output it produced when we ran it.
Before you start
- An API key. Create a free account; it comes with free tokens every month. Put the key in an environment variable so it stays out of your code:
export BLOODWEB_KEY=your_key - Python 3 with the requests library:
pip install requests - The input file in the same folder:
voice.wav. Use your own; that is the name the code expects.
The code
Save it as audio-convert.py and run python3 audio-convert.py.
import os
import requests
resp = requests.post(
"https://bloodweb.net/api/v1/audio-convert",
headers={"Authorization": f"Bearer {os.environ['BLOODWEB_KEY']}"},
files={"file": open("voice.wav", "rb")},
data={"to": "mp3", "bitrate": "128"},
timeout=120,
)
if not resp.ok:
raise SystemExit(f"{resp.status_code}: {resp.json()['error']['message']}")
with open("voice.mp3", "wb") as f:
f.write(resp.content)
What you get
Tested 19 October 2026: this exact code ran against our test copy of the API, which runs the same service code as bloodweb.net, and produced this.
It writes voice.mp3: an MP3 file, 2.1 seconds, 33 KB.
Change the call
Every option the Audio converter takes. Add or change them the same way as the ones in the code.
torequired: Output format. One of: mp3, ogg, opus, m4a, wav, flac.bitrate: kbps, for MP3, OGG, Opus and M4A. 128 is fine for speech, 192 or more for music.channels: Keep the channels, or mix to mono or stereo. One of: keep, mono, stereo.sample_rate: Hz. Opus only takes 8000, 16000, 24000 or 48000; other values become 48000. One of: keep, 8000, 16000, 22050, 24000, 32000, 44100, 48000.start: Start at this many seconds in.duration: Keep this many seconds.normalize: Even out the loudness to -16 LUFS, the usual level for podcasts and voice.fade_in: Fade in over this many seconds.fade_out: Fade out over this many seconds at the end.
If it fails
A failed call is not charged. The answer is JSON with an error object; the code above prints its message. The usual ones:
- 401
missing_keyorinvalid_key:BLOODWEB_KEYis not set in the shell that runs the code, or the key was revoked. - 415
unsupported_type: the file is not a type this service reads. The type is read from the file itself, so renaming a file does not change it. - 413
file_too_large: the file is over the limit on the service page. - 402
insufficient_tokens: the balance does not cover the call. Top up in the dashboard. - 429
rate_limited: too many calls at once. Wait the seconds in theRetry-Afterheader and send it again.
Every code and its fix is in the docs.
Next
- The Audio converter page: every option, the limits, and Try it now in your browser.
- Getting started: keys, errors and rate limits for all the services.