{"id":19809641,"url":"https://github.com/openvpi/audio-slicer","last_synced_at":"2025-05-16T15:04:09.556Z","repository":{"id":64946842,"uuid":"531032143","full_name":"openvpi/audio-slicer","owner":"openvpi","description":"Python script that slices audio with silence detection","archived":false,"fork":false,"pushed_at":"2024-06-08T01:46:28.000Z","size":24,"stargazers_count":808,"open_issues_count":4,"forks_count":277,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-03T11:09:14.287Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openvpi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-31T10:20:03.000Z","updated_at":"2025-03-16T05:34:03.000Z","dependencies_parsed_at":"2024-12-13T11:11:45.746Z","dependency_job_id":"29df0e76-e31f-4b69-b5a7-b19312369ae8","html_url":"https://github.com/openvpi/audio-slicer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openvpi%2Faudio-slicer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openvpi%2Faudio-slicer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openvpi%2Faudio-slicer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openvpi%2Faudio-slicer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openvpi","download_url":"https://codeload.github.com/openvpi/audio-slicer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248564847,"owners_count":21125412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T09:17:39.719Z","updated_at":"2025-04-12T11:49:23.182Z","avatar_url":"https://github.com/openvpi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Audio Slicer\n\nPython script that slices audio with silence detection\n\n---\n\nThis is the 2.0 version of audio slicer, which provides:\n\n- Great improvements on speed (400x compared to previous 15x)\n- Enhanced slicing logic with fewer errors\n\nThe 1.0 version can be found [here](https://github.com/openvpi/audio-slicer/tree/old).\n\nGUI version can be found [here](https://github.com/flutydeer/audio-slicer).\n\n## Algorithm\n\n### Silence detection\n\nThis script uses RMS (root mean score) to measure the quiteness of the audio and detect silent parts. RMS values of each frame (frame length set as **hop size**) are calculated and all frames with an RMS below the **threshold** will be regarded as silent frames.\n\n### Audio slicing\n\nOnce the valid (sound) part reached **min length** since last slice and a silent part longer than **min interval** are detected, the audio will be sliced apart from the frame(s) with the lowest RMS value within the silent area. Long silence parts may be deleted.\n\n## Requirements\n\n### If you are using Python API\n\n```bash\npip install numpy\n```\n\n### If you are using CLI\n\n```shell\npip install librosa\npip install soundfile\n```\n\nor\n\n```shell\npip install -r requirements.txt\n```\n\n## Usage\n\n### Using Python API\n\n```python\nimport librosa  # Optional. Use any library you like to read audio files.\nimport soundfile  # Optional. Use any library you like to write audio files.\n\nfrom slicer2 import Slicer\n\naudio, sr = librosa.load('example.wav', sr=None, mono=False)  # Load an audio file with librosa.\nslicer = Slicer(\n    sr=sr,\n    threshold=-40,\n    min_length=5000,\n    min_interval=300,\n    hop_size=10,\n    max_sil_kept=500\n)\nchunks = slicer.slice(audio)\nfor i, chunk in enumerate(chunks):\n    if len(chunk.shape) \u003e 1:\n        chunk = chunk.T  # Swap axes if the audio is stereo.\n    soundfile.write(f'clips/example_{i}.wav', chunk, sr)  # Save sliced audio files with soundfile.\n```\n\n### Using CLI\n\nThe script can be run with CLI as below:\n\n```bash\npython slicer2.py audio [--out OUT] [--db_thresh DB_THRESH] [--min_length MIN_LENGTH] [--min_interval MIN_INTERVAL] [--hop_size HOP_SIZE] [--max_sil_kept MAX_SIL_KEPT]\n```\n\nwhere `audio` refers to the audio to be sliced, `--out` defaults to the same directory as the audio, and other options have default values as listed [here](#Parameters).\n\n## Parameters\n\n### sr\n\nSampling rate of the input audio.\n\n### db_threshold\n\nThe RMS threshold presented in dB. Areas where all RMS values are below this threshold will be regarded as silence. Increase this value if your audio is noisy. Defaults to -40.\n\n### min_length\n\nThe minimum length required for each sliced audio clip, presented in milliseconds. Defaults to 5000.\n\n### min_interval\n\nThe minimum length for a silence part to be sliced, presented in milliseconds. Set this value smaller if your audio contains only short breaks. The smaller this value is, the more sliced audio clips this script is likely to generate. Note that this value must be smaller than min_length and larger than hop_size. Defaults to 300.\n\n### hop_size\n\nLength of each RMS frame, presented in milliseconds. Increasing this value will increase the precision of slicing, but will slow down the process. Defaults to 10.\n\n### max_silence_kept\n\nThe maximum silence length kept around the sliced audio, presented in milliseconds. Adjust this value according to your needs. Note that setting this value does not mean that silence parts in the sliced audio have exactly the given length. The algorithm will search for the best position to slice, as described above. Defaults to 1000.\n\n## Performance\n\nThis script runs over 400x faster than real-time on an Intel i7 8750H CPU. Speed may vary according to your CPU and your disk. Though `Slicer` is thread-safe, multi-threading does not seem neccessary due to the I/O bottleneck.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenvpi%2Faudio-slicer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenvpi%2Faudio-slicer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenvpi%2Faudio-slicer/lists"}