Skip to content

Instantly share code, notes, and snippets.

@SamuelAlgheriniAI
Last active July 2, 2021 08:21
Show Gist options
  • Save SamuelAlgheriniAI/0c3abed928485e64fc4b227bb6516606 to your computer and use it in GitHub Desktop.
Save SamuelAlgheriniAI/0c3abed928485e64fc4b227bb6516606 to your computer and use it in GitHub Desktop.
Pre-processing the file. Conversion to wav and moving to conversion folder
#Pre-processing function
def preprocessing(path_base, path_converted_audio):
for file in os.listdir(path_base):
filename, file_extension = os.path.splitext(file)
print("\nFile name: " + file)
if file_extension == ".wav":
file_to_process = file
shutil.copy(path_base + file, path_converted_audio + file)
elif file_extension in extension_to_convert:
subprocess.call(['ffmpeg', '-i', path_base + file,
path_base + filename + ".wav"])
shutil.move(path_base + filename + ".wav", path_converted_audio + filename + ".wav")
print(file + " is converted into " + filename +".wav")
else:
print("ERROR: Unsupported file type - "+ file + " was not converted. Modify the pre-processing stage to convert *" + file_extension + " files.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment