Skip to content

shahabfar/SplitBySilence

Repository files navigation

🎧 SplitBySilence

A lightweight C# .NET 9 console application that automatically splits a long MP3 file into individual songs using silence detection powered by FFmpeg.

It finds silent gaps between songs, extracts each track losslessly (no re-encoding), and saves them as separate MP3 files with a CSV manifest.
Ideal for DJ mixes, continuous albums, or any long recordings.


🚀 Features

  • 🎵 Detects silence gaps between songs automatically
  • ⚡ Splits MP3s without quality loss (stream-copy mode)
  • 📊 Generates a CSV manifest with timestamps
  • 🧠 Adjustable parameters (--silenceDb, --minSilence, --minTrack, --pad)
  • 💻 Cross-platform — runs on Windows, macOS, or Linux (requires FFmpeg)
  • 🪶 Written in pure .NET 9 C#, no external NuGet dependencies

🛠️ Requirements

Component Purpose Installation
.NET 9 SDK Run/build the console app Download .NET 9
FFmpeg Detect & cut silence Download FFmpeg or winget install Gyan.FFmpeg

After installing FFmpeg, verify it’s on your PATH:

ffmpeg -version
ffprobe -version

🧩 Installation

Clone this repo:

git clone https://github.com/<your-username>/SplitBySilence.git
cd SplitBySilence

Build it:

dotnet build

▶️ Usage

Quick start

dotnet run --project SplitBySilence.csproj -- --input "C:\music\long_mix.mp3"

This will:

  • Detect silences (default: quieter than -35 dB for ≥ 1.5 s)
  • Split tracks
  • Save them in a folder next to the input, e.g. long_mix_split/
  • Generate long_mix_tracks.csv with segment info

Advanced options

Option Default Description
--input (required) Path to input MP3 file
--outdir auto Output directory
--silenceDb -35 Silence threshold (lower = more sensitive)
--minSilence 1.5 Minimum silence duration (seconds)
--minTrack 60 Minimum valid track length (seconds)
--pad 0.0 Add/subtract seconds to cut edges
--ffmpeg ffmpeg Custom path to ffmpeg
--ffprobe ffprobe Custom path to ffprobe
--dry-run Detect & show planned splits (no files written)
--verbose Print detailed detection logs

Example:

dotnet run --project SplitBySilence.csproj -- \
  --input "C:\mixes\session.mp3" \
  --silenceDb -40 \
  --minSilence 2.0 \
  --minTrack 75 \
  --pad 0.15

📂 Output structure

📁 long_mix_split/
 ├── long_mix_track_01.mp3
 ├── long_mix_track_02.mp3
 ├── long_mix_track_03.mp3
 ├── ...
 └── long_mix_tracks.csv

The CSV manifest contains:

Index,Start,End,Duration,File
1,0.0,243.5,4:03,long_mix_track_01.mp3
2,243.5,496.2,4:13,long_mix_track_02.mp3
...

🧠 How it works

  1. FFmpeg “silencedetect” filter analyzes the waveform:

    silencedetect=noise=-35dB:d=1.5
    
  2. Logs silence start/end points → parsed by C#

  3. Segments are computed and exported via ffmpeg -ss -to -c copy (no re-encode)

This ensures frame-accurate, lossless MP3 cuts.


🖥️ Run from VS Code

  1. Install Visual Studio Code

  2. Open folder:

    code .
  3. Press F5 to build & run (launch config included in .vscode/launch.json)


🧰 Build & publish as a standalone EXE

You can package it for Windows:

dotnet publish -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true

Output:

bin\Release\net9.0\win-x64\publish\SplitBySilence.exe

Then you can run:

SplitBySilence.exe --input "C:\music\album.mp3"

💡 Tips

  • Lower --silenceDb (e.g. -40) if silences aren’t detected.
  • Increase --minSilence (e.g. 2.0) to avoid false splits.
  • Use --dry-run --verbose to preview detection logs before cutting.
  • Works with WAV, FLAC, or other formats too — just change the file extension.

🧾 Example screenshot

(Replace this with your own later) Example output screenshot


🧑‍💻 Author

Majid — Software Developer & Solution Architect 🔗 LinkedIn • 💻 [.NET / Blazor / FFmpeg enthusiast]


🪪 License

This project is licensed under the MIT License — free to use, modify, and distribute.


⭐ Support

If you find this helpful, please ⭐ the repo — it helps others discover it!

About

Automatically split MP3 files into songs by detecting silence — built with .NET and FFmpeg

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages