Last active
February 19, 2024 20:57
-
-
Save danlei/6b57aa8bc9f5b3d13ed34e8ad3689c9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.10 | |
# trim noise from forvo audio files | |
# experiment with treshold (in db) as needed | |
import sys | |
from pydub import AudioSegment | |
from pydub.silence import split_on_silence | |
if not 2 <= len(sys.argv) <= 3: | |
sys.exit("usage: forvo-trim FILE [TRESHOLD]") | |
input_file = sys.argv[1] | |
tresh = float(sys.argv[2]) if len(sys.argv) > 2 else -33 | |
audio = AudioSegment.from_file(input_file) | |
chunks = split_on_silence(audio, | |
silence_thresh=tresh, | |
min_silence_len=150) | |
if not len(chunks): | |
sys.exit("no audio chunk found") | |
chunks[0].export('trimmed_' + input_file, format='mp3') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment