Skip to main content

Audio Clip Extractor

This utility allows one to cut multiple clips from a single or multiple audio files.

The idea of this project came up when I was doing some Shadowing. The problem was that the dialogs were long, so if I wanted to practice a certain phrase or word I would have to manually rewind it. So I thought, if I can split them in different files I'd be able to practice each separately.

Also, since this script can embed text as metadata in the outputted clips themselves the next step would be to create an application that takes all these clips and automatically arranges them in a way that makes shadowing even easier to practice.

Requirements

This project depends on FFMPEG. It can be downloaded for free here. After installing it, you can either add it to your PATH or pass it as an argument --ffmpeg <ffmpeg_path>.

For each audio file there needs to be a file with the same name but with .txt extension with the respective clips' timestamps (check under section How it works for further information).

Note: In future versions it will be possible to pass timestamps as optional arguments.

Installation

Use pip with following command:

   $ pip install audioclipextractor

How it works

$ ace audio_to_cut_from.mp3

The script looks for a file with the same name as the audio file but with the extension .txt. The format of this file is the same as the track labels' file that you can export using Audacity by going to the menu File > Export Labels... or Tracks > Edit Labels... and then Export.

<begin_clip:seconds> <end_clip:seconds> [<text>]

Begin clip CANNOT be equal to or greater than End clip.

Example:

1.50    6.20    Hello World!
10      24.70   Because I said so.
33.85   36

The <text> part is completely optional, but if provided it will be embedded in the respective outputted clip as metadata. The default name is m_text but it can be set by passing the option argument --text-var <desired_name> or -m <desired_name>.

It can also be piped to, example:

$ find . -name '*.mp3' -type f | audioclipextractor --zip

But since we can't have a single specifications file for multiple audio files, this isn't very useful yet. In the future we will be able to, for instance, cut out the first 15s for each file.

Comand Line Options

--version, -V
    Prints the version of the script

--zip, -z
    Archive the output in a zip container

--ffmpeg <FILEPATH>
    Specify the FFMPEG executable path

--output-dir, -o
    Set the output directory

--text-name, -m
    Specify the name of the embedded text variable

[files]
    Audio files to process

How to use it in your projects

I recommend installing virtualenv to create an isolated environment.

Example:

$ pip install virtualenv
$ virtualenv venv
$ source venv/bin/activate
$ pip install audioclipextractor
(venv) $ ace audio_to_cut_from.mp3

example.py

from audioclipextractor import AudioClipExtractor, SpecsParser

# Inicialize the extractor
ext = AudioClipExtractor('/path/to/audio/file.mp3', '/path/to/ffmpeg')

# Define the clips to extract
# It's possible to pass a file instead of a string
specs = '''
    3.5     17      Winter is coming.
    26      32.4    Summer child.
    40      58.9    Hodor. Hodor. Hodor.
'''

# Extract the clips according to the specs and save them as a zip archive
ext.extract_clips(specs, '/path/to/output/directory', zip_output=True)

Notes

This is still a work in progress. Feel free to use it, fork it and give suggestions.

License

AudioClipCutter is available under the MIT License.

Metadata

Release files for audioclipextractor 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for audioclipextractor 0.3.0
File Size Uploaded Provenance Actions
audioclipextractor-0.3.0.tar.gz 11.8 kB Without provenance Details for audioclipextractor-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for audioclipextractor 0.3.0
File Interpreter ABI Platform Actions
audioclipextractor-0.3.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for audioclipextractor-0.3.0-py2.py3-none-any.whl

Total release size: 26.6 kB

Release files / audioclipextractor-0.3.0.tar.gz

Download URL audioclipextractor-0.3.0.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8e663e464fb8fd3538aeb59b92c32d89741608435aa81532590787c9552227ab
BLAKE2b-256 checksum
How to use checksums
170fd9f1390a99e9688ca2668e707c87e9f6a7c9777e82a64cca79a1667fd399
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.6

Release files / audioclipextractor-0.3.0-py2.py3-none-any.whl

Download URL audioclipextractor-0.3.0-py2.py3-none-any.whl
Size 14.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
956e234ee6839d708442f9df29f87f7941028ef825d2b9c52b322fa5bac58239
BLAKE2b-256 checksum
How to use checksums
2d939f64fe7450500ae9640ca4f57c649f611bcda423775047d0ee31d12174ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.6

Security for audioclipextractor 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page