'commit'
This commit is contained in:
@@ -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';
|
||||
|
Reference in New Issue
Block a user