audio_helper.cli module
Audio Helper — the audio-helper command line.
The single command-line surface of the package: every library operation
is reachable as a subcommand, implemented with click so shell
completion (click.shell_completion), colored --help and nested
groups come for free.
Subcommands
convert— re-encode an audio file (sample rate / channels / codec)duration— print the duration in seconds of an audio filechunk— extract a[start, end]slice from an audio filesilence— write a silent audio file of a given durationconcat— concatenate several audio files head-to-tailroomtone— mix pink/white/brown ambient noise onto a speech tracksplit— split an audio file into fixed-duration chunksseparate— run Demucs source separation (needs the[demucs]extra)resemblance— MFCC-based similarity score between two audio files
Design notes
Flags are named (
--input/--output/ …) rather than positional: audio commands take several paths and a bare positional order is easy to get backwards.Every subcommand is a thin dispatch onto
audio_helper.main; the result goes to stdout (a plain path for single-file outputs, one path per line for multi-file ones, JSON for structured results) so shell pipelines can chain on it.A library exception is caught by
main()and printed as one cleanError: ...line + exit 1; click only handles its own exceptions.
Usage Example
>>> # audio-helper convert --input in.mp3 --output out.wav --freq 44100
>>> # audio-helper duration --input in.mp3
>>> # audio-helper chunk --input in.mp3 --start 3.0 --end 8.5 --output cut.mp3
>>> # audio-helper silence --duration 5 --output silence.wav
>>> # audio-helper concat --inputs a.mp3 b.mp3 c.mp3 --output all.mp3
>>> # audio-helper roomtone --input speech.wav --output speech-rt.wav --db -42
>>> # audio-helper split --input in.mp3 --output-dir chunks/ --seconds 30
>>> # audio-helper separate --input mix.mp3 --output-dir stems/
>>> # audio-helper resemblance --a a.mp3 --b b.mp3
- audio_helper.cli.main()[source]
Console entry point (
audio-helper).Click’s own error handling only special-cases
ClickException/Abort(and a broken pipe); a plain library exception (e.g. anAssertionErrorfrom an invalid audio file, or anffmpeg.Error) would otherwise propagate as a raw Python traceback instead of a clean CLI error. This wraps the whole invocation and translates that last case into a one-line stderr message + exit 1 — click’s own control flow (usage errors,--help, an explicitsys.exitin a subcommand, e.g.separate’s missing-torch guard above) already raisesSystemExit, aBaseExceptionthis does not catch, so it passes through untouched.- Return type:
None