Created
May 3, 2020 09:13
-
-
Save punkyoon/e7fea38af4cce3c2e75c0e55e63633da to your computer and use it in GitHub Desktop.
WAV to MP3
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
| import click | |
| import os | |
| from glob import glob | |
| from pydub import AudioSegment | |
| @click.command() | |
| @click.argument('src') | |
| @click.argument('dst') | |
| def wav2mp3(src, dst): | |
| src = glob(src) | |
| for wav_file in src: | |
| # Get file name | |
| file_name = os.path.basename(wav_file) | |
| file_name = os.path.splitext(file_name)[0] | |
| # Convert to mp3 | |
| print(f'[INFO] Start to convert {file_name}') | |
| try: | |
| AudioSegment.from_file(wav_file) \ | |
| .export(os.path.join(dst, f'{file_name}.mp3'), format='mp3') | |
| except Exception as e: | |
| print(f'[Error] Fail to convert {file_name}\n -----> {e}') | |
| else: | |
| print(f'[SUCCESS] Success to convert {file_name}') | |
| if __name__ == '__main__': | |
| wav2mp3() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use
Requiring ffmpeg