This commit is contained in:
2025-09-06 10:57:28 +08:00
parent b7c7dd1766
commit b9de5438ec
5 changed files with 6 additions and 1 deletions

View File

@@ -42,10 +42,15 @@ async def save_audio(audio: UploadFile = File(...), txt: str = Form(...)):
# 修改MP3保存路径为UPLOAD_DIR使用相同文件名前缀
mp3_file_name = os.path.splitext(file_name)[0] + ".mp3"
mp3_file_path = os.path.join(UPLOAD_DIR, mp3_file_name)
"""
ffmpeg -i audio_00008a1143e64d75bd51e7b0c9e7ce2b.wav \
-ar 16000 -ac 1 -acodec libmp3lame -b:a 64k \
out_16k_16bit_mono.mp3
"""
try:
# 使用ffmpeg将wav转换为mp3
subprocess.run(
["ffmpeg", "-i", temp_file, "-y", mp3_file_path],
["ffmpeg", "-i", temp_file, "-ar", "16000", "-ac", "1", "-acodec", "libmp3lame", "-b:a", "128k", "-y", mp3_file_path],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE