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 file

  • chunk — extract a [start, end] slice from an audio file

  • silence — write a silent audio file of a given duration

  • concat — concatenate several audio files head-to-tail

  • roomtone — mix pink/white/brown ambient noise onto a speech track

  • split — split an audio file into fixed-duration chunks

  • separate — 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 clean Error: ... 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

Author

Warith Harchaoui, Ph.D. — https://linkedin.com/in/warith-harchaoui/

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. an AssertionError from an invalid audio file, or an ffmpeg.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 explicit sys.exit in a subcommand, e.g. separate’s missing-torch guard above) already raises SystemExit, a BaseException this does not catch, so it passes through untouched.

Return type:

None