'commit'
This commit is contained in:
0
dsLightRag/Routes/XunFeiRoute.py
Normal file
0
dsLightRag/Routes/XunFeiRoute.py
Normal file
@@ -19,7 +19,7 @@ sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
|
||||
from Config.Config import XF_APPID, XF_APIKEY, XF_APISECRET
|
||||
|
||||
@router.post("/save-audio")
|
||||
async def save_audio(audio: UploadFile = File(...), txt: str = Form(...), language: str = Form("english")): # 添加语言参数,默认英文
|
||||
async def save_audio(audio: UploadFile = File(...), txt: str = Form(...)):
|
||||
"""保存音频文件并评分"""
|
||||
temp_file = None
|
||||
try:
|
||||
@@ -39,16 +39,18 @@ 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保存路径为UPLOAD_DIR,使用相同文件名前缀
|
||||
mp3_file_name = os.path.splitext(file_name)[0] + ".mp3"
|
||||
mp3_file_path = os.path.join(UPLOAD_DIR, mp3_file_name)
|
||||
try:
|
||||
# 使用ffmpeg将wav转换为mp3
|
||||
subprocess.run(
|
||||
["ffmpeg", "-i", temp_file, "-y", mp3_temp_file],
|
||||
["ffmpeg", "-i", temp_file, "-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,8 +61,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,
|
||||
language=language, # 使用动态参数
|
||||
audio_file=mp3_file_path, # 使用新的MP3路径
|
||||
txt=txt
|
||||
)
|
||||
results, eval_time = evaluator.run_evaluation()
|
||||
|
BIN
dsLightRag/Routes/__pycache__/XunFeiRoute_cn.cpython-310.pyc
Normal file
BIN
dsLightRag/Routes/__pycache__/XunFeiRoute_cn.cpython-310.pyc
Normal file
Binary file not shown.
BIN
dsLightRag/Routes/__pycache__/XunFeiRoute_en.cpython-310.pyc
Normal file
BIN
dsLightRag/Routes/__pycache__/XunFeiRoute_en.cpython-310.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user