Split long audio files into chapter tracks by matching repeated divider clips.
Project description
audio-chapter-splitter
A small Python tool to split long MP3 child stories into separate chapter files automatically.
I created this project to prepare audio files for a Toniebox. Many children's stories are distributed as one long MP3, which makes it harder for a child to jump back and forth between story sections. By splitting the audio into separate chapter tracks, the child can navigate more easily.
What Problem This Solves
If a children's story is stored as a single long MP3, playback devices like the Toniebox treat it as one continuous file. That means:
- no natural chapter navigation
- harder to repeat a favorite part
- harder to skip to the next section
This script helps by finding recurring audio markers, for example a title song or short transition melody, and using them as automatic split points.
How It Works
My workflow starts outside Python:
- I record or prepare the full story as one long audio file in Audacity.
- In Audacity, I listen for short sections that repeat throughout the story, for example the title melody or short transition melodies between chapters.
- I export those short repeated sections as separate MP3 files.
- These short files become the reference clips, or "divider melodies", that the script searches for.
The script compares the full story audio against one or more of these short reference audio files. When it detects a strong match, it treats that point as a chapter boundary. It then exports each chapter as its own MP3 file.
This is useful when the story contains repeated audio cues between chapters.
Typical Use Case
Example:
- record a full children's story in Audacity and export it as one long
story.mp3 - cut out a short
divider-melody.mp3clip that appears between chapters - optionally cut out a
title-theme.mp3clip if the title melody also repeats at useful positions
The script scans the full story file, detects these repeated divider melodies, and writes chapter files into an output folder.
Requirements
- Python 3
ffmpeginstalled and available on your systemPATH- Python dependencies from
requirements.txt
Installation
Install the Python dependencies with:
pip install -r requirements.txt
Or install the project as a local package with its console entry point:
pip install .
You also need ffmpeg installed separately on your system, because it is not a Python package and is required by pydub for MP3 handling.
To install ffmpeg:
-
Official download page: https://ffmpeg.org/download.html
-
Windows:
- the official FFmpeg project links to Windows builds here: https://www.gyan.dev/ffmpeg/builds/
- extract it to a local folder
- add the
binfolder containingffmpeg.exeto your systemPATH - example: if you extracted FFmpeg to
C:\tools\ffmpeg, addC:\tools\ffmpeg\binto yourPATH
-
macOS:
- install it with Homebrew using
brew install ffmpeg
- install it with Homebrew using
-
Linux:
- install it with your package manager, for example
sudo apt install ffmpeg
- install it with your package manager, for example
To verify the installation, run:
ffmpeg -version
If that command prints version information, ffmpeg is installed correctly and available on your PATH.
On Windows, extending the PATH variable means adding the folder that contains ffmpeg.exe to the list of folders that Windows searches when you run commands in a terminal.
Example:
- if
ffmpeg.exeis located inC:\tools\ffmpeg\bin - add
C:\tools\ffmpeg\binto thePATHvariable - then you can run
ffmpeg -versionfrom any terminal window without typing the full file path
Typical Windows steps:
- Open the Start menu and search for
Environment Variables. - Open
Edit the system environment variables. - Click
Environment Variables.... - Under
User variablesorSystem variables, selectPath. - Click
Edit. - Click
New. - Paste the full path to the FFmpeg
binfolder, for exampleC:\tools\ffmpeg\bin. - Confirm with
OKin all open dialogs. - Open a new terminal window and run
ffmpeg -version.
On Linux, extending the PATH variable means adding the folder that contains the ffmpeg executable to the list of folders your shell searches when you run commands.
In many Linux installations, ffmpeg is installed by the package manager into a standard location and no manual PATH change is needed.
If you install a custom build in a separate folder, you may need to add that folder yourself.
Example:
- if the
ffmpegexecutable is located in/opt/ffmpeg/bin - add
/opt/ffmpeg/binto yourPATH - then you can run
ffmpeg -versionfrom any terminal window without typing the full file path
Temporary change for the current terminal session:
export PATH="/opt/ffmpeg/bin:$PATH"
Persistent change for future terminal sessions:
- Open your shell configuration file, for example
~/.bashrcor~/.zshrc. - Add this line:
export PATH="/opt/ffmpeg/bin:$PATH"
- Save the file.
- Reload the configuration with
source ~/.bashrcor open a new terminal. - Run
ffmpeg -versionto verify it works.
If you want a quick setup helper instead of installing manually:
- Windows: run
setup_story_env.bat - Linux or macOS: run
sh setup_story_env.sh
Both scripts create a virtual environment in venv/ and install the Python dependencies from requirements.txt.
Files Expected By The Script
The script now accepts file paths through CLI arguments, so your audio files do not need fixed names. You need:
- one main audio file, for example
story.mp3 - one or more reference clips, for example
divider-melody.mp3andtitle-theme.mp3
By default, output is written to:
chapter_output/
Usage
Run the script with your input file and one or more reference clips:
audio-chapter-splitter \
--input story.mp3 \
--reference divider-melody.mp3 \
--reference title-theme.mp3 \
--output chapter_output \
--output-format mp3
The script will export separate chapter MP3 files into the output folder.
You can inspect all available options with:
audio-chapter-splitter --help
You can still run it directly without installing the console script:
python split_audio_by_reference.py --input story.mp3 --reference divider-melody.mp3
Example Terminal Output
Example run:
$ audio-chapter-splitter --input story.mp3 --reference divider-melody.mp3 --reference title-theme.mp3 --output chapter_output
Progress: [########################################] 100% ETA: 0s
Saved chapter 1: chapter_output/chapter_1.mp3
Saved chapter 2: chapter_output/chapter_2.mp3
Saved chapter 3: chapter_output/chapter_3.mp3
This gives you separate chapter files that can be copied to your playback device instead of one long story file.
Configuration
Important CLI options:
--inputfor the main audio file--referencefor each divider melody--outputfor the export folder--output-formatfor the exported chapter format (mp3orwav)--min-distancefor the minimum gap between detected chapter markers--hop-lengthfor chroma analysis tuning--threshold-scalefor detection sensitivity--keep-tempto keep the temporary WAV file for debugging
Limitations
- The script works best when chapter boundaries contain a clearly repeated audio cue.
- If the reference clip is noisy or inconsistent, detection may be inaccurate.
- The current implementation exports chapter files as
chapter_1.mp3,chapter_2.mp3, and so on. - If no divider melody is detected, the script exports the full audio as a single chapter file.
Legal Note
This tool is intended for processing audio that you created yourself or are otherwise authorized to use. You are responsible for ensuring that your use of any source audio complies with applicable copyright, licensing, and platform rules. This project is not affiliated with or endorsed by tonies.
Release Checklist
Before publishing a new release:
- run
python -m unittest discover -s tests -v - run
python -m build - verify
audio-chapter-splitter --helpworks in a clean virtual environment - review the README example command and version number
- create a git tag for the release, for example
v0.2.0
Why This Project Exists
This is a practical tool built for a real family use case: turning long children's audio stories into chapter-based tracks that are easier for children to control on a Toniebox.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file audio_chapter_splitter-0.2.0.tar.gz.
File metadata
- Download URL: audio_chapter_splitter-0.2.0.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d21b7de1b8af026e72e0c86c4a155c5787f9985a001bbe13d918df0bd4a90729
|
|
| MD5 |
e480087cd32aaef5d7e9c96b26679200
|
|
| BLAKE2b-256 |
6a73f06ef6d95e52571af01134749ea3ebd83964a4fc414831beb57580e967ea
|
Provenance
The following attestation bundles were made for audio_chapter_splitter-0.2.0.tar.gz:
Publisher:
publish.yml on Columbo/audio-chapter-splitter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
audio_chapter_splitter-0.2.0.tar.gz -
Subject digest:
d21b7de1b8af026e72e0c86c4a155c5787f9985a001bbe13d918df0bd4a90729 - Sigstore transparency entry: 1016340064
- Sigstore integration time:
-
Permalink:
Columbo/audio-chapter-splitter@86346d53419d291c1c31e02c04f476b664506be5 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Columbo
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@86346d53419d291c1c31e02c04f476b664506be5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file audio_chapter_splitter-0.2.0-py3-none-any.whl.
File metadata
- Download URL: audio_chapter_splitter-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f55f0091dfd04e6b834343219b18f132badd399505de4698f56f58cecae5825
|
|
| MD5 |
76eb9c11b60c1a31f27f92e9d7824a3a
|
|
| BLAKE2b-256 |
340f40151aeb64b8d6ba627eb68ff99ec5fd23adce9dec5d8352812856d75638
|
Provenance
The following attestation bundles were made for audio_chapter_splitter-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on Columbo/audio-chapter-splitter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
audio_chapter_splitter-0.2.0-py3-none-any.whl -
Subject digest:
9f55f0091dfd04e6b834343219b18f132badd399505de4698f56f58cecae5825 - Sigstore transparency entry: 1016340106
- Sigstore integration time:
-
Permalink:
Columbo/audio-chapter-splitter@86346d53419d291c1c31e02c04f476b664506be5 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Columbo
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@86346d53419d291c1c31e02c04f476b664506be5 -
Trigger Event:
release
-
Statement type: