Created
June 14, 2023 00:48
-
-
Save JohannSuarez/a4e1493528e01296f1624893f5a9467c to your computer and use it in GitHub Desktop.
Unsilence ( removes silent parts of an audio file )
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/python3 | |
import argparse | |
import subprocess | |
import os | |
def remove_silence(filename, noise_tolerance='-30dB', silence_duration='0.5'): | |
# Extract the base filename and extension | |
base_filename, extension = os.path.splitext(filename) | |
# Construct the output filename by appending '_cleaned' to the base filename | |
output_filename = f'{base_filename}_cleaned{extension}' | |
command = f'ffmpeg -i "{filename}" -af silenceremove=stop_periods=-1:stop_duration={silence_duration}:stop_threshold={noise_tolerance} "{output_filename}"' | |
subprocess.run(command, shell=True) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='Remove silence from an audio file.') | |
parser.add_argument('filename', type=str, help='The input filename') | |
args = parser.parse_args() | |
remove_silence(args.filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment