/docs · General · Practical
Check audio quality in CI: fail a build when a file breaks your rules
A short Python script and a GitHub workflow that measure each audio file with the AudioLab API, compare the numbers with limits you set, and fail the build with a message that says why.
Updated Oct 12, 2026
Who this is for
You ship audio out of a pipeline: text-to-speech prompts, voice-agent recordings, podcast episodes, game or app sound. A build should stop when a file is too quiet, clips, is band-limited or is noisy, before a listener hears it.
It is for teams that set their own limits. AudioLab measures the file; whether a number passes is your rule. It does not judge how natural a voice sounds and it does not read the words. See what AudioLab does not do.
What you get
- A script,
audio_gate.py, that measures each file you give it, checks your limits and exits with a code your CI understands. Its only dependency is theaudiolabtoolspackage. - A limits file,
gate.json, with one entry per number. - A workflow,
audio-gate.yml, that runs the script on pull requests and measures only the audio files the pull request adds or changes. - Every failing line names the number, its value and the limit, and says how far to trust the number: its status and its margin. The person who reads a red build knows what they are looking at. See how to read a response.
Before you start
- Get a key. It is free and needs no card: sign in on /account and generate one. In GitHub, store it as a repository secret named
AUDIOLAB_KEY. Never commit it. - Know that the files leave the runner. Every file the gate measures is sent to the AudioLab API, hosted in the EU, and only numbers come back. See “Privacy and limits” below. If your audio is not allowed to leave your own systems, this is not the tool for the build. The workspace measures in your browser and uploads nothing, but by hand, not in a build.
- Know what it costs. The ten numbers come from three analyses: the loudness numbers from one call, the voice numbers from a second, the bandwidth from a third. The script asks only for the calls your limits need. The limits file below uses all three, so a file costs three calls; a limits file with loudness numbers only costs one call a file. The unit is minutes of audio: a file counts its decoded length, rounded up to the next whole minute, and the same file costs nothing more that day (UTC), so three calls on one file cost its minutes once. The free tier is 300 minutes a month and 60 requests a minute.
- Python 3.9 or newer, and the package:
pip install audiolabtools
Your limits
{
"integratedLufs": { "min": -26, "max": -16 },
"truePeakDb": { "max": -1 },
"clipping": { "oneOf": ["None"] },
"signalToNoiseDb": { "min": 30 },
"bandwidthHz": { "min": 7000 }
}
Each entry names one of the ten numbers and gives a min, a max or both. clipping is a word, so it gets a list of the words you allow in oneOf. These limits are examples: set your own from your own good recordings. Take twenty you consider good and use their 5th and 95th percentile, as step 7 of “How to read them” in the comparison guide says.
The script
"""Fail a build when an audio file breaks your rules.
python audio_gate.py gate.json audio/intro.wav audio/outro.wav
gate.json holds the limits, one entry per number:
https://audiolab.tools/docs/start/audio-quality-gate-in-ci
Every file is sent to the AudioLab API; only numbers come back.
Exit code: 0 every file passes, 1 a file breaks a rule, 2 a file could not be checked
(a key, a limit of your plan, no network). A build must not pass on 2.
"""
from __future__ import annotations
import json
import sys
import time
from audiolabtools import (
ApiTimeout,
ApiUnreachable,
AudioLab,
AudioLabError,
AuthenticationError,
MissingApiKey,
PlanLimitError,
RateLimitError,
)
PASSED, BROKEN, COULD_NOT_CHECK = 0, 1, 2
# The same for every file, so there is no point in going on: a key that is refused,
# a limit of your plan, a minute that is full, no network.
STOPS = (
AuthenticationError, PlanLimitError, RateLimitError,
MissingApiKey, ApiUnreachable, ApiTimeout,
)
NEAR = " within the margin: the number cannot say if the file is past it"
def broken_rules(numbers, rules):
"""The rules one file breaks, one line each.
A line carries the status and the margin of the number: how far to trust it.
A number that could not be measured breaks no rule: the gate could not tell (see main).
"""
lines = []
for field, rule in rules.items():
m = numbers[field]
trust = (m.status or "no status") + (f", margin {m.margin}" if m.margin else "")
if m.value is None:
continue
if "oneOf" in rule:
if m.value not in rule["oneOf"]:
allowed = ", ".join(rule["oneOf"])
lines.append(f"{field} is {m.value}, allowed: {allowed} ({trust})")
else:
mg = m.margin
slack = max(mg.plus_minus or 0, mg.plus or 0, mg.minus or 0) if mg else 0
low, high = rule.get("min"), rule.get("max")
past = []
if low is not None and m.value < low:
past.append(("below the minimum", low))
if high is not None and m.value > high:
past.append(("above the maximum", high))
for word, limit in past:
lines.append(f"{field} is {m.value} {m.unit}, {word} {limit} ({trust})")
if abs(m.value - limit) <= slack + 1e-9:
lines.append(NEAR)
return lines
def measure(client, path, fields, wait=time.sleep):
"""The numbers of one file. On a full minute the API says how long to wait: do that once."""
try:
return client.ten_numbers(path, only=fields)
except RateLimitError as e:
wait(e.retry_after or 60)
return client.ten_numbers(path, only=fields)
def main(argv, client=None, out=print, wait=time.sleep):
if len(argv) < 3:
out("usage: python audio_gate.py gate.json file [file ...]")
return COULD_NOT_CHECK
with open(argv[1], encoding="utf-8") as f:
rules = json.load(f)
client = client or AudioLab() # reads AUDIOLAB_KEY
result, broken, unchecked = PASSED, 0, 0
for path in argv[2:]:
try:
numbers = measure(client, path, list(rules), wait)
except STOPS as e:
out(f"STOP {path}\n {e}")
return COULD_NOT_CHECK
except AudioLabError as e: # a problem with this file only: say so, check the others
out(f"ERROR {path}\n {e}")
unchecked += 1
result = COULD_NOT_CHECK
continue
lines = broken_rules(numbers, rules)
# Not measured is not broken: the gate could not tell, so exit 2, not 1.
missing = [f"{field} could not be measured" for field in rules if numbers[field].value is None]
out(f"{'FAIL' if lines else 'N/A ' if missing else 'ok '} {path}")
for line in lines + missing:
out(f" {line}")
if lines:
broken += 1
result = max(result, BROKEN)
if missing:
unchecked += 1
result = COULD_NOT_CHECK
checked = len(argv) - 2
out(f"{checked} file{'' if checked == 1 else 's'} checked, {broken} break a rule, "
f"{unchecked} could not be checked")
return result
if __name__ == "__main__":
sys.exit(main(sys.argv))
It reads the limits, asks ten_numbers for the numbers the limits name (only=, so nothing else is called), and prints one line per broken rule. Two things it decides for you. A full minute is waited out once, as long as the API asks in its Retry-After, because that is what the API says to do. A key that is refused, a limit of your plan or no network stops the run at the first file, because the same would happen to every file; a problem with one file is reported and the others are still checked.
The workflow
name: audio quality gate
on:
pull_request:
paths: ["audio/**"]
jobs:
gate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install audiolabtools
- name: Measure the audio files this pull request adds or changes
env:
AUDIOLAB_KEY: ${{ secrets.AUDIOLAB_KEY }}
BASE: ${{ github.base_ref }}
run: |
mapfile -d '' files < <(git diff -z --name-only --diff-filter=AM \
"origin/$BASE...HEAD" -- 'audio/*.wav' 'audio/*.mp3' 'audio/*.flac')
if [ "${#files[@]}" -eq 0 ]; then echo "No audio files changed."; exit 0; fi
python tools/audio_gate.py tools/gate.json "${files[@]}"
Put audio_gate.py and gate.json in tools/, and the audio in audio/. The last step passes the script only the files that this pull request adds or changes, so an old file is not measured again on every push. A pull request from a fork gets none of your secrets. Without a key the script runs as the keyless trial, which allows only 20 calls a month, so the gate soon stops with a limit error and exit code 2. Decide whether you skip the job for forks.
What a failed check looks like
FAIL audio/prompt-welcome.wav
integratedLufs is -31.5 LUFS, below the minimum -26 (validated, margin ±0.1 LU)
1 file checked, 1 break a rule, 0 could not be checked
This is the output of the script on the example limits, for a file that is far too quiet. The exit code is 1, so the build fails, and the log says which file, which number, which limit and how far to trust the number.
When a number is closer to the limit than its margin, the line says so. The same file against a minimum of -31.4 instead of -26:
FAIL audio/prompt-welcome.wav
integratedLufs is -31.5 LUFS, below the minimum -31.4 (validated, margin ±0.1 LU)
within the margin: the number cannot say if the file is past it
1 file checked, 1 break a rule, 0 could not be checked
How to read it
- Exit 1 means the file broke a rule. Exit 2 means the gate could not tell. The line carries the error code and the page that explains it, for example
https://audiolab.tools/docs/errors#quota_exceeded. A build must not pass on exit 2: a gate that cannot reach the API has not checked anything. - Read the margin before you argue with a failure. A line followed by “within the margin” is a number that cannot tell you whether the file is past the limit, because the number itself can be off by more than the distance. When the margin is not symmetric, the script uses the larger side. Either loosen the limit by the margin or fix the file. The script does not decide for you.
- A limit on a proxy compares, it does not state a fact.
speechRatioandlongSilencesare proxies, and the line says so. They are good at catching a big change and poor at policing a decimal. - Start loose, then tighten. Run the gate with wide limits for a while and read what it prints, then narrow the limits to what your good recordings show. A gate that fails every build gets switched off.
- A run measures what it is given. Changing
gate.jsondoes not measure the files that are already in the repository. After you change a limit, run the script once over the whole folder.
What it cannot do
- It measures the file, not what is said. A file inside every limit can still be the wrong sentence, a poor voice or the wrong language.
- It has no memory. It does not compare a file with an earlier version or with a reference. To compare vendors or versions over many sentences, use the comparison guide.
- It does not run offline. The engine is not published as a package, so every file goes to the API.
- Its numbers have the status and the margin they have. See what AudioLab does not do.
Privacy and limits
- Your audio is not kept. It is analysed in Frankfurt; while that runs, the file may pass through temporary scratch space that is deleted as soon as the analysis is done. A file you upload through the signed-upload route is removed within the hour. We keep the numbers and, if you let us, the file name. See /privacy.
- Limits. Free: 300 minutes a month, 60 requests a minute. Plus: 1,500 minutes, 120 a minute. A local file over 4 MB is uploaded once through the signed-upload route before it is measured: the upload has its own count of requests a minute, apart from the analysis, and it is not a call. A request we refuse before measuring (a wrong path or parameter, a recording that is too long or cannot be read) costs no minutes. When the minutes run out, the API answers 402 with the code
voice_minutes_exhausted; new minutes arrive on the 1st (the minutes of your plan) or with a package. An error tells you what to do: /docs/errors. - Where you stand.
AudioLab().usage()returns the plan and the minutes used this month against the limits. Reading it is free and costs no minutes.
Next in General docs
Jobs: send the file, get the answer later →
POST /v1/jobs runs any analysis route in the background after we reply: an id at once, the result by polling or by a signed webhook, every job on your account page. One request for any file up to 150 MB through the upload door.
More in General docs
- Practical
Compare voice-agent and TTS vendors, and check conversational audio
Three API calls, ten numbers, and how far to trust each one: a guide for QA teams comparing voice-agent, text-to-speech or voice-isolation vendors.
- Practical
QC in one call: one verdict against a spec
POST /v1/qc measures a file and holds it against a delivery target, the starting limits or your own: pass, warn or fail, rule by rule, with the status and margin of every measure.
- Practical
Audit a dataset of conversations: where the audio really comes from
Measure a folder of call, voice-agent or text-to-speech recordings for upsampling, a lossy source, splices, mono in disguise, clipping and bit depth, 20 files at a time, and know when the audio is uploaded and when it is not.
- Practical
Is my audio upsampled?
One call per file and one field to read: bandLimit.upsampled says yes, no or cannot-say, with the reason in plain words. What to do with each answer, how often each came out in our tests, and what it cannot see.
- Intro
Read a response: what each field means and how far to trust it
A real answer from the API, field by field: what it says, its status and margin, and what you may and may not conclude from it.
- Intro
What AudioLab does not do
The limits of the analysis, stated plainly: it does not transcribe, predict recognition errors, score naturalness, identify speakers or measure latency, and its background hints are guesses.
- Intro
Changes and deprecation: what changes, when, and how you find out
The promise behind /v1, what counts as a change that needs notice, how we announce it, and what is deprecated today.