Skip to content

Commit

Permalink
add config
Browse files Browse the repository at this point in the history
  • Loading branch information
SUC-DriverOld committed May 11, 2024
1 parent e28aef2 commit 1f00ead
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Use `audio_processor.py`:
```bash
"-i", "--input_dir", Input directory containing audio files
"-o", "--output_dir", Output directory to save processed audio files
"target_loudness", default=-23, Target loudness
"-target", "--target_loudness", default=-23, Target loudness
"-type", "--loudness_type", default="LUFS", choices=["LUFS", "dBFS", "Peak_dBFS", "RMSdB"], Type of loudness to match
"--export_format", default="wav", choices=["wav", "flac", "mp3"], Audio export format
"--mp3_bitrate", default=320, choices=[128, 192, 256, 320], MP3 bitrate in kbps
Expand All @@ -53,7 +53,7 @@ Use `audio_processor.py`:
Example:

```bash
python audio_processor.py -i input -o output -23 -type LUFS -export_format mp3 -mp3_bitrate 320
python audio_processor.py -i input -o output -target -23 -type LUFS --export_format mp3 --mp3_bitrate 320
```

## Notes
Expand Down
4 changes: 2 additions & 2 deletions README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ python gui.py
```bash
"-i", "--input_dir", Input directory containing audio files
"-o", "--output_dir", Output directory to save processed audio files
"target_loudness", default=-23, Target loudness
"-target", "--target_loudness", default=-23, Target loudness
"-type", "--loudness_type", default="LUFS", choices=["LUFS", "dBFS", "Peak_dBFS", "RMSdB"], Type of loudness to match
"--export_format", default="wav", choices=["wav", "flac", "mp3"], Audio export format
"--mp3_bitrate", default=320, choices=[128, 192, 256, 320], MP3 bitrate in kbps
Expand All @@ -53,7 +53,7 @@ python gui.py
例如:

```bash
python audio_processor.py -i input -o output -23 -type LUFS -export_format mp3 -mp3_bitrate 320
python audio_processor.py -i input -o output -target -23 -type LUFS --export_format mp3 --mp3_bitrate 320
```

## 一些说明
Expand Down
20 changes: 12 additions & 8 deletions audio_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ def process_audio(input_dir, output_dir, target_loudness, loudness_type="LUFS",
shutil.rmtree(temp_dir)


def main():
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Audio processing API")
parser.add_argument("-i", "--input_dir", type=str, required=True,
help="Input directory containing audio files")
parser.add_argument("-o", "--output_dir", type=str, required=True,
help="Output directory to save processed audio files")
parser.add_argument("target_loudness", type=float,
parser.add_argument("-target", "--target_loudness", type=float,
default=-23, help="Target loudness (default: -23)")
parser.add_argument("-type", "--loudness_type", type=str, default="LUFS", choices=["LUFS", "dBFS", "Peak_dBFS", "RMSdB"],
help="Type of loudness to match (default: LUFS)")
Expand All @@ -189,8 +189,16 @@ def main():
args.input_dir, args.output_dir, args.target_loudness, args.loudness_type, args.export_format, args.mp3_bitrate, args.ffmpeg_sample_rate, args.ffmpeg_bit_depth
))

with open('config.json', 'r') as config_file:
config = json.load(config_file)
try:
with open('config.json', 'r') as config_file:
config = json.load(config_file)
except FileNotFoundError:
config = {
"export_format": "wav",
"mp3_bitrate": 320,
"ffmpeg_sample_rate": 48000,
"ffmpeg_bit_depth": 32
}

config["export_format"] = args.export_format
config["mp3_bitrate"] = args.mp3_bitrate
Expand All @@ -211,7 +219,3 @@ def main():

process_audio(args.input_dir, args.output_dir,
args.target_loudness, loudness_type)


if __name__ == "__main__":
main()

0 comments on commit 1f00ead

Please sign in to comment.