diff --git a/dsLightRag/Routes/XueBan.py b/dsLightRag/Routes/XueBan.py index e46ec4bd..9a7401dd 100644 --- a/dsLightRag/Routes/XueBan.py +++ b/dsLightRag/Routes/XueBan.py @@ -46,8 +46,8 @@ async def upload_audio(file: UploadFile = File(...)): } # 删除临时文件 - os.remove(temp_file_path) - logger.info(f"临时文件已删除: {temp_file_path}") + #os.remove(temp_file_path) + #logger.info(f"临时文件已删除: {temp_file_path}") # 返回识别结果 return JSONResponse(content={ diff --git a/dsLightRag/Routes/__pycache__/XueBan.cpython-310.pyc b/dsLightRag/Routes/__pycache__/XueBan.cpython-310.pyc index 7ccaafdd..b3103743 100644 Binary files a/dsLightRag/Routes/__pycache__/XueBan.cpython-310.pyc and b/dsLightRag/Routes/__pycache__/XueBan.cpython-310.pyc differ diff --git a/dsLightRag/static/XueBan.html b/dsLightRag/static/XueBan.html index 8015df08..9052cf3c 100644 --- a/dsLightRag/static/XueBan.html +++ b/dsLightRag/static/XueBan.html @@ -111,6 +111,7 @@ const audioUrl = URL.createObjectURL(audioBlob); console.log("录音URL:", audioUrl); // 这里可以调用ASR服务 + uploadAudioToServer(audioBlob); }; mediaRecorder.start(); @@ -145,6 +146,64 @@ } } + // 上传音频到服务器 + function uploadAudioToServer(audioBlob) { + console.log("开始上传音频到服务器"); + const formData = new FormData(); + formData.append('file', audioBlob, 'recording.wav'); + + fetch('/api/xueban/upload-audio', { + method: 'POST', + body: formData + }) + .then(response => { + if (!response.ok) { + throw new Error('服务器响应错误'); + } + return response.json(); + }) + .then(data => { + console.log("ASR识别结果:", data); + if (data.success) { + showAsrResult(data.data.text); + } else { + alert('音频识别失败: ' + data.message); + } + }) + .catch(error => { + console.error("上传音频失败:", error); + alert('上传音频失败: ' + error.message); + }); + } + + // 显示ASR识别结果 + function showAsrResult(text) { + // 检查是否已存在结果显示元素 + let resultElement = document.getElementById('asrResult'); + if (!resultElement) { + resultElement = document.createElement('div'); + resultElement.id = 'asrResult'; + resultElement.style.position = 'fixed'; + resultElement.style.bottom = '80px'; + resultElement.style.left = '20px'; + resultElement.style.zIndex = '1000'; + resultElement.style.padding = '10px 15px'; + resultElement.style.backgroundColor = 'rgba(0, 123, 255, 0.9)'; + resultElement.style.color = 'white'; + resultElement.style.borderRadius = '5px'; + resultElement.style.boxShadow = '0 2px 10px rgba(0, 0, 0, 0.2)'; + document.body.appendChild(resultElement); + } + + resultElement.textContent = '识别结果: ' + text; + resultElement.style.display = 'block'; + + // 5秒后自动隐藏 + setTimeout(() => { + resultElement.style.display = 'none'; + }, 5000); + } + // 初始化看板娘 - 简化为Sample.html的工作版本 function initL2Dwidget() { const modelId = getUrlParam('id') || 'koharu';