Skip to content

Instantly share code, notes, and snippets.

@deepwilson
Last active February 6, 2019 06:02
Show Gist options
  • Save deepwilson/28c1013e064e0e36d2f8f54876d8a7ee to your computer and use it in GitHub Desktop.
Save deepwilson/28c1013e064e0e36d2f8f54876d8a7ee to your computer and use it in GitHub Desktop.
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