This commit is contained in:
2025-09-06 09:19:46 +08:00
parent 0b67beb83f
commit 28f7f3bc41
24 changed files with 21 additions and 4 deletions

View File

@@ -37,13 +37,29 @@ async def save_audio(audio: UploadFile = File(...), txt: str = Form(...)):
shutil.copy2(temp_file, file_path)
logger.info(f"已保存文件到: {file_path}")
# 添加wav转mp3功能
import subprocess
mp3_temp_file = 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],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
logger.info(f"已将wav转换为mp3: {mp3_temp_file}")
except subprocess.CalledProcessError as e:
logger.error(f"ffmpeg转换失败: {e.stderr.decode()}")
raise Exception(f"音频格式转换失败: {e.stderr.decode()}")
# 2. 讯飞评分
from KeDaXunFei.XunFeiAudioEvaluator import XunFeiAudioEvaluator
evaluator = XunFeiAudioEvaluator(
appid=XF_APPID,
api_key=XF_APIKEY,
api_secret=XF_APISECRET,
audio_file=temp_file,
audio_file=mp3_temp_file, # 使用转换后的mp3文件
language="english",
txt=txt
)