'commit'
This commit is contained in:
@@ -19,7 +19,7 @@ from Config.Config import XF_APPID, XF_APISECRET, XF_APIKEY
|
||||
class XunFeiAudioEvaluator:
|
||||
"""讯飞语音评测类"""
|
||||
|
||||
def __init__(self, appid, api_key, api_secret, audio_file, language):
|
||||
def __init__(self, appid, api_key, api_secret, audio_file, language, txt):
|
||||
self.appid = appid
|
||||
self.api_key = api_key
|
||||
self.api_secret = api_secret
|
||||
@@ -28,6 +28,7 @@ class XunFeiAudioEvaluator:
|
||||
self.host_url = "wss://ise-api.xfyun.cn/v2/open-ise"
|
||||
self.websocket_url = ""
|
||||
self.evaluation_results = {}
|
||||
self.txt = txt
|
||||
|
||||
def generate_auth_url(self):
|
||||
"""生成鉴权URL"""
|
||||
@@ -106,7 +107,7 @@ class XunFeiAudioEvaluator:
|
||||
"cmd": "ssb",
|
||||
"auf": "audio/L16;rate=16000",
|
||||
"aue": "lame",
|
||||
"text": '\uFEFF' + "[content]\nnice to meet you."
|
||||
"text": '\uFEFF' + "[content]\n" + self.txt
|
||||
},
|
||||
"data": {
|
||||
"status": 0,
|
||||
@@ -225,7 +226,7 @@ class XunFeiAudioEvaluator:
|
||||
summary += f"\n=== 单词级别得分 ===\n"
|
||||
for i, word in enumerate(self.evaluation_results['words']):
|
||||
dp_msg = self._get_dp_message_description(word['dp_message'])
|
||||
summary += f"{i+1}. {word['content']}: {word['total_score']:.4f} ({dp_msg})\n"
|
||||
summary += f"{i + 1}. {word['content']}: {word['total_score']:.4f} ({dp_msg})\n"
|
||||
|
||||
return summary
|
||||
|
||||
@@ -272,16 +273,16 @@ if __name__ == '__main__':
|
||||
appid = XF_APPID
|
||||
api_secret = XF_APISECRET
|
||||
api_key = XF_APIKEY
|
||||
#audio_file = "./1.mp3"
|
||||
audio_file=r'D:\dsWork\dsProject\dsLightRag\static\audio\audio_1f0a8c47db2d4f9ba7674055a352cab8.wav'
|
||||
# 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")
|
||||
evaluator = XunFeiAudioEvaluator(appid, api_key, api_secret, audio_file, "english","nice to meet you.")
|
||||
|
||||
# 运行评测
|
||||
results, eval_time = evaluator.run_evaluation()
|
||||
|
||||
# 输出评测结果摘要
|
||||
print("\n" + "="*50)
|
||||
print("\n" + "=" * 50)
|
||||
print(evaluator.get_evaluation_summary())
|
||||
print(f"总评测时间: {eval_time}")
|
||||
print("="*50)
|
||||
print("=" * 50)
|
||||
|
Binary file not shown.
@@ -4,8 +4,7 @@ import uuid
|
||||
import tempfile
|
||||
import shutil
|
||||
import sys
|
||||
import logging
|
||||
from fastapi import APIRouter, UploadFile, File
|
||||
from fastapi import APIRouter, UploadFile, File, Form
|
||||
|
||||
# 配置日志
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -20,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(...)):
|
||||
async def save_audio(audio: UploadFile = File(...), txt: str = Form(...)):
|
||||
"""保存音频文件并评分"""
|
||||
temp_file = None
|
||||
try:
|
||||
@@ -45,7 +44,8 @@ async def save_audio(audio: UploadFile = File(...)):
|
||||
api_key=XF_APIKEY,
|
||||
api_secret=XF_APISECRET,
|
||||
audio_file=temp_file,
|
||||
language="english"
|
||||
language="english",
|
||||
txt=txt
|
||||
)
|
||||
results, eval_time = evaluator.run_evaluation()
|
||||
print(evaluator.get_evaluation_summary())
|
||||
|
Binary file not shown.
@@ -450,7 +450,11 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 添加英文朗读文本输入区域 -->
|
||||
<div class="text-container">
|
||||
<h3 style="color: #5eead4; margin-bottom: 10px;">📝 请朗读以下文本</h3>
|
||||
<textarea id="readingText" rows="4" style="width: 100%; padding: 12px; border-radius: 8px; background: rgba(15, 23, 42, 0.7); border: 1px solid rgba(94, 234, 212, 0.2); color: #e2e8f0; font-size: 16px; resize: vertical; font-family: inherit;">Hello everyone! Nice to meet you. Today is a beautiful day. I am learning English pronunciation with this tool.</textarea>
|
||||
</div>
|
||||
<div class="visualizer">
|
||||
<canvas id="visualizerCanvas"></canvas>
|
||||
</div>
|
||||
@@ -760,7 +764,9 @@
|
||||
const fileName = `recording_${Date.now()}.${extensions[format]}`;
|
||||
|
||||
formData.append('audio', this.recordedBlob, fileName);
|
||||
|
||||
// 添加朗读文本到表单数据
|
||||
const readingText = document.getElementById('readingText').value;
|
||||
formData.append('txt', readingText);
|
||||
try {
|
||||
this.simulateUploadProgress();
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user