Last active
July 15, 2018 07:37
-
-
Save nvgordeev/adb154ebbc4c842fe8c577030d633eff to your computer and use it in GitHub Desktop.
Convert audio with pydub
This file contains hidden or 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
| # 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) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python 3 used