Skip to content

Instantly share code, notes, and snippets.

@nvgordeev
Last active July 15, 2018 07:37
Show Gist options
  • Select an option

  • Save nvgordeev/adb154ebbc4c842fe8c577030d633eff to your computer and use it in GitHub Desktop.

Select an option

Save nvgordeev/adb154ebbc4c842fe8c577030d633eff to your computer and use it in GitHub Desktop.
Convert audio with pydub
# pip install pydub
# https://github.com/jiaaro/pydub/
import pydub
# IMPORTANT: ffmpeg binaries should be included to system PATH, https://www.ffmpeg.org/
from pathlib import Path
FOLDER = r'E:\\mus\\convert\\before\\'
EXPORT_FOLDER = r'E:\\mus\\convert\\after\\'
FROM_FORMAT = 'flac'
TO_FORMAT = 'mp3'
FROM_EXT = '.' + FROM_FORMAT
TO_EXT = '.' + TO_FORMAT
pathlist = Path(FOLDER).glob('**/*' + FROM_EXT)
for path in pathlist:
file_full_path = str(path)
file_name = path.parts[-1]
print ('Processing file ' + file_full_path)
flac_audio = pydub.AudioSegment.from_file(file_full_path, FROM_FORMAT)
flac_audio.export(EXPORT_FOLDER + file_name.rstrip(FROM_EXT) + TO_EXT, format=TO_FORMAT)
@nvgordeev
Copy link
Author

python 3 used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment