Sin2pi commited on
Commit
f544df3
·
verified ·
1 Parent(s): cb33cdd

Delete remove_silence_from_samples.ipynb

Browse files
Files changed (1) hide show
  1. remove_silence_from_samples.ipynb +0 -49
remove_silence_from_samples.ipynb DELETED
@@ -1,49 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": null,
6
- "metadata": {},
7
- "outputs": [],
8
- "source": [
9
- "import os, librosa\n",
10
- "\n",
11
- "top_db=20\n",
12
- "def remove_silence(input_file, output_file, top_db=top_db):\n",
13
- "\n",
14
- " y, sr = sf.read(input_file)\n",
15
- " intervals = librosa.effects.split(y, top_db=top_db)\n",
16
- " if len(intervals) == 0:\n",
17
- " with open('output.txt', 'a') as f:\n",
18
- " f.write(input_file, file=f)\n",
19
- " else:\n",
20
- " y_trimmed = []\n",
21
- " for start, end in intervals:\n",
22
- " y_trimmed.extend(y[start:end])\n",
23
- " if not os.path.exists(output_file): \n",
24
- " sf.write(output_file, y_trimmed, sr)\n",
25
- "\n",
26
- "def process_directory(input_dir, output_dir, top_db=top_db):\n",
27
- " if not os.path.exists(output_dir):\n",
28
- " os.makedirs(output_dir)\n",
29
- "\n",
30
- " for filename in os.listdir(input_dir):\n",
31
- " if filename.endswith(\".mp3\"):\n",
32
- " input_file = os.path.join(input_dir, filename)\n",
33
- " output_file = os.path.join(output_dir, filename)\n",
34
- " remove_silence(input_file, output_file, top_db)\n",
35
- " \n",
36
- "input_dir = folder_path\n",
37
- "output_dir = folder_path\n",
38
- "process_directory(folder_path, (folder_path + \"_trimmed/\"))"
39
- ]
40
- }
41
- ],
42
- "metadata": {
43
- "language_info": {
44
- "name": "python"
45
- }
46
- },
47
- "nbformat": 4,
48
- "nbformat_minor": 2
49
- }