Last active
February 6, 2019 06:02
-
-
Save deepwilson/28c1013e064e0e36d2f8f54876d8a7ee 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
import os | |
def convert_to_mp3(file,source_dir = "",dest_dir = "",reduce_noise = False): | |
"""Converts file to mp3 | |
Creates source_dir if required | |
Returns ffmpeg exit code""" | |
file_ext = file.split(".")[-1] | |
if not os.path.isdir(dest_dir): | |
os.mkdir(dest_dir) | |
ffmpeg_command = "ffmpeg -y " | |
ffmpeg_command += "-i "+source_dir+"/"+file+" " | |
"""Reduce background noise""" | |
if reduce_noise: | |
ffmpeg_command += "-af \"highpass=f=200, lowpass=f=3000\" " | |
ffmpeg_command += dest_dir+"/"+file[:-(len(file_ext)+1)]+".mp3" | |
print(ffmpeg_command) | |
return os.system(ffmpeg_command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment