From 180cf67672368d6a5758493c3d6996817ade9f0a Mon Sep 17 00:00:00 2001 From: jrafaaael Date: Wed, 5 Oct 2022 12:37:50 -0400 Subject: [PATCH 1/2] add script --- scripts/AudioConverter/audio-converter.py | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 scripts/AudioConverter/audio-converter.py diff --git a/scripts/AudioConverter/audio-converter.py b/scripts/AudioConverter/audio-converter.py new file mode 100644 index 0000000..28f936f --- /dev/null +++ b/scripts/AudioConverter/audio-converter.py @@ -0,0 +1,51 @@ +import subprocess +import os +import argparse + + +parser = argparse.ArgumentParser( + description='A program to convert audio to another audio format' +) +parser.add_argument( + '-p', + '--path', + type=str, + help=''' +The full path of file to convert OR +the full path of folder that contains all files to convert' + ''', + required=True +) +parser.add_argument( + '-e', + '--extension', + type=str, + help='The type of extension to convert the audio', + default='.mp3', + required=False +) + + +def convert(file, extension): + file_name, _ = file.split('.') + output_name = file_name + extension + subprocess.run(['ffmpeg', '-i', file, output_name]) + + +def convert_all(path, extension): + for _, _, files in os.walk(path): + for file in files: + convert(file, extension) + + +if __name__ == "__main__": + args = parser.parse_args() + path = args.path + extension = args.extension + + os.chdir(os.path.dirname(path)) + + if (os.path.isdir(path)): + convert_all(path=path, extension=extension) + else: + convert(file=path, extension=extension) From 2e2ecefe9ec8c1cc5317f377ccb0c5a1baa08618 Mon Sep 17 00:00:00 2001 From: jrafaaael Date: Wed, 5 Oct 2022 12:37:57 -0400 Subject: [PATCH 2/2] add readme file --- scripts/AudioConverter/README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 scripts/AudioConverter/README.md diff --git a/scripts/AudioConverter/README.md b/scripts/AudioConverter/README.md new file mode 100644 index 0000000..59702ac --- /dev/null +++ b/scripts/AudioConverter/README.md @@ -0,0 +1,28 @@ +# Audio Converter + +CLI tool to convert an audio file from one extension to another (e.g. mp3 to wav) + +## Requirements +- [FFmpeg](https://ffmpeg.org/) + +## Usage + +### Convert all audio files in a specific directory +```bash +python3 audio-converter.py -p -e +``` + +e.g. +```bash +python3 audio-converter.py -p /home/username/Music -e .wav +``` + +### Convert specific audio file +```bash +python3 audio-converter.py -p -e +``` + +e.g. +```bash +python3 audio-converter.py -p /home/username/Music/test.mp3 -e .wav +```