diff --git a/dsLightRag/KeDaXunFei/XunFeiAudioEvaluator.py b/dsLightRag/KeDaXunFei/XunFeiAudioEvaluator.py index cc40d0d2..9e6e5b57 100644 --- a/dsLightRag/KeDaXunFei/XunFeiAudioEvaluator.py +++ b/dsLightRag/KeDaXunFei/XunFeiAudioEvaluator.py @@ -6,6 +6,7 @@ import json import ssl import time import xml.etree.ElementTree as ET +import base64 from datetime import datetime from time import mktime from urllib.parse import urlencode @@ -163,10 +164,11 @@ class XunFeiAudioEvaluator: # 查找read_chapter节点 read_chapter = root.find('.//read_chapter') if read_chapter is not None: + # 保持字段名一致,使用completeness_score self.evaluation_results = { 'accuracy_score': float(read_chapter.get('accuracy_score', 0)), 'fluency_score': float(read_chapter.get('fluency_score', 0)), - 'completeness_score': float(read_chapter.get('integrity_score', 0)), # 修复字段名 + 'completeness_score': float(read_chapter.get('integrity_score', 0)), 'standard_score': float(read_chapter.get('standard_score', 0)), 'total_score': float(read_chapter.get('total_score', 0)), 'word_count': int(read_chapter.get('word_count', 0)), @@ -206,7 +208,8 @@ class XunFeiAudioEvaluator: summary += f"总得分: {self.evaluation_results.get('total_score', 0):.4f}\n" summary += f"准确度得分: {self.evaluation_results.get('accuracy_score', 0):.4f}\n" summary += f"流畅度得分: {self.evaluation_results.get('fluency_score', 0):.4f}\n" - summary += f"完整度得分: {self.evaluation_results.get('integrity_score', 0):.4f}\n" + # 修复这里,使用completeness_score + summary += f"完整度得分: {self.evaluation_results.get('completeness_score', 0):.4f}\n" summary += f"标准度得分: {self.evaluation_results.get('standard_score', 0):.4f}\n" summary += f"单词数量: {self.evaluation_results.get('word_count', 0)}\n" summary += f"是否被拒绝: {'是' if self.evaluation_results.get('is_rejected', False) else '否'}\n" @@ -269,8 +272,8 @@ if __name__ == '__main__': appid = XF_APPID api_secret = XF_APISECRET api_key = XF_APIKEY - audio_file = "./1.mp3" - + #audio_file = "./1.mp3" + audio_file=r'D:\dsWork\dsProject\dsLightRag\static\audio\audio_1f0a8c47db2d4f9ba7674055a352cab8.wav' # 创建评测器实例 evaluator = XunFeiAudioEvaluator(appid, api_key, api_secret, audio_file, "english") diff --git a/dsLightRag/KeDaXunFei/__pycache__/XunFeiAudioEvaluator.cpython-310.pyc b/dsLightRag/KeDaXunFei/__pycache__/XunFeiAudioEvaluator.cpython-310.pyc index 5cc0845c..d5f16b6d 100644 Binary files a/dsLightRag/KeDaXunFei/__pycache__/XunFeiAudioEvaluator.cpython-310.pyc and b/dsLightRag/KeDaXunFei/__pycache__/XunFeiAudioEvaluator.cpython-310.pyc differ diff --git a/dsLightRag/Routes/XunFeiRoute.py b/dsLightRag/Routes/XunFeiRoute.py index 8045807a..7701bea2 100644 --- a/dsLightRag/Routes/XunFeiRoute.py +++ b/dsLightRag/Routes/XunFeiRoute.py @@ -4,6 +4,7 @@ import uuid import tempfile import shutil import sys +import logging from fastapi import APIRouter, UploadFile, File # 配置日志 @@ -30,7 +31,13 @@ async def save_audio(audio: UploadFile = File(...)): content = await audio.read() with open(temp_file, "wb") as f: f.write(content) - + + # 3. 保存到正式目录 + file_name = f"audio_{uuid.uuid4().hex}.wav" + file_path = os.path.join(UPLOAD_DIR, file_name) + shutil.copy2(temp_file, file_path) + logger.info(f"已保存文件到: {file_path}") + # 2. 讯飞评分 from KeDaXunFei.XunFeiAudioEvaluator import XunFeiAudioEvaluator evaluator = XunFeiAudioEvaluator( @@ -41,11 +48,8 @@ async def save_audio(audio: UploadFile = File(...)): language="english" ) results, eval_time = evaluator.run_evaluation() - - # 3. 保存到正式目录 - file_name = f"audio_{uuid.uuid4().hex}.wav" - file_path = os.path.join(UPLOAD_DIR, file_name) - shutil.copy2(temp_file, file_path) + print(evaluator.get_evaluation_summary()) + return { "success": True, diff --git a/dsLightRag/Routes/__pycache__/XunFeiRoute.cpython-310.pyc b/dsLightRag/Routes/__pycache__/XunFeiRoute.cpython-310.pyc index 7e6a0245..2695cba8 100644 Binary files a/dsLightRag/Routes/__pycache__/XunFeiRoute.cpython-310.pyc and b/dsLightRag/Routes/__pycache__/XunFeiRoute.cpython-310.pyc differ diff --git a/dsLightRag/static/XunFei/audio_evaluation.html b/dsLightRag/static/XunFei/audio_evaluation.html index ace94d82..e13e553e 100644 --- a/dsLightRag/static/XunFei/audio_evaluation.html +++ b/dsLightRag/static/XunFei/audio_evaluation.html @@ -3,7 +3,7 @@
-