'commit'
This commit is contained in:
@@ -39,16 +39,17 @@ async def save_audio(audio: UploadFile = File(...), txt: str = Form(...), langua
|
||||
|
||||
# 添加wav转mp3功能
|
||||
import subprocess
|
||||
mp3_temp_file = os.path.join(temp_dir, f"temp_{uuid.uuid4().hex}.mp3")
|
||||
mp3_file_path = os.path.join(temp_dir, f"temp_{uuid.uuid4().hex}.mp3")
|
||||
try:
|
||||
# 使用ffmpeg将wav转换为mp3
|
||||
subprocess.run(
|
||||
["ffmpeg", "-i", temp_file, "-y", mp3_temp_file],
|
||||
["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
|
||||
)
|
||||
logger.info(f"已将wav转换为mp3: {mp3_temp_file}")
|
||||
logger.info(f"已将wav转换为mp3: {mp3_file_path}")
|
||||
except subprocess.CalledProcessError as e:
|
||||
logger.error(f"ffmpeg转换失败: {e.stderr.decode()}")
|
||||
raise Exception(f"音频格式转换失败: {e.stderr.decode()}")
|
||||
@@ -59,7 +60,7 @@ async def save_audio(audio: UploadFile = File(...), txt: str = Form(...), langua
|
||||
appid=XF_APPID,
|
||||
api_key=XF_APIKEY,
|
||||
api_secret=XF_APISECRET,
|
||||
audio_file=mp3_temp_file,
|
||||
audio_file=mp3_file_path,
|
||||
language=language, # 使用动态参数
|
||||
txt=txt
|
||||
)
|
||||
|
Reference in New Issue
Block a user