mirror of
https://gitea.cookies.4d.ink/Cookies/CookiesChartConverter.git
synced 2025-10-26 03:02:39 +00:00
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
import sys
|
|
from pathlib import Path
|
|
from subprocess import run
|
|
from loguru import logger
|
|
# 设置工作目录
|
|
WORK_DIR = Path("work/audio")
|
|
|
|
# 确保工作目录存在
|
|
WORK_DIR.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
def convert_awb_to_wav(awb, output_wav):
|
|
"""使用 vgmstream-cli 将 AWB 文件转换为 WAV 文件"""
|
|
run(["vgmstream-cli","-o",output_wav,awb])
|
|
|
|
|
|
|
|
def convert_wav_to_mp3(wav, output_mp3):
|
|
"""使用 ffmpeg 将 WAV 文件转换为 44100Hz 的 MP3 文件"""
|
|
run(["ffmpeg", "-y", "-i", wav, "-ar", "44100", output_mp3])
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) < 3:
|
|
logger.info("用法: python acb2mp3.py 输入文件 输出文件")
|
|
sys.exit(1)
|
|
|
|
input_file = sys.argv[1]
|
|
output_file = sys.argv[2]
|
|
|
|
# 获取输入文件的扩展名
|
|
input_path = Path(input_file)
|
|
output_path = Path(output_file)
|
|
|
|
# 判断输入文件是否是 .acb 文件
|
|
if input_path.suffix.lower() == ".acb":
|
|
# 假设输入文件关联的 .awb 文件在同一目录下
|
|
awb_file = input_path.with_suffix(".awb")
|
|
logger.info(awb_file)
|
|
if awb_file.exists():
|
|
# 将 .awb 转换为 WAV
|
|
wav_file = WORK_DIR / "output.wav"
|
|
convert_awb_to_wav(str(awb_file), str(wav_file))
|
|
logger.info(f"AWB 转换成功,生成文件: {wav_file}")
|
|
|
|
# 将 WAV 转换为 MP3
|
|
mp3_file = output_path.with_suffix(".mp3")
|
|
convert_wav_to_mp3(str(wav_file), str(mp3_file))
|
|
logger.info(f"WAV 转换为 MP3 成功,生成文件: {mp3_file}")
|
|
else:
|
|
logger.error(f"未找到对应的 AWB 文件: {awb_file}")
|
|
else:
|
|
logger.error(f"输入文件不是 .acb 文件: {input_path}")
|