'commit'
This commit is contained in:
@@ -12,19 +12,20 @@ const resultDiv = document.getElementById('result');
|
||||
const resultContent = document.getElementById('resultContent');
|
||||
|
||||
// 语言切换时自动填充示例文本
|
||||
languageSelect.addEventListener('change', () => {
|
||||
if (languageSelect.value === 'chinese') {
|
||||
textInput.value = '窗前明月光,疑是地上霜。';
|
||||
} else {
|
||||
textInput.value = 'Nice to meet you.';
|
||||
}
|
||||
});
|
||||
// 移除语言切换事件监听
|
||||
// languageSelect.addEventListener('change', () => {
|
||||
// if (languageSelect.value === 'chinese') {
|
||||
// textInput.value = '窗前明月光,疑是地上霜。';
|
||||
// } else {
|
||||
// textInput.value = 'Nice to meet you.';
|
||||
// }
|
||||
// });
|
||||
|
||||
// 页面加载时自动填充中文示例
|
||||
window.addEventListener('load', () => {
|
||||
textInput.value = '窗前明月光,疑是地上霜。';
|
||||
stopBtn.disabled = true;
|
||||
});
|
||||
// 移除页面加载事件监听
|
||||
// window.addEventListener('load', () => {
|
||||
// textInput.value = '窗前明月光,疑是地上霜。';
|
||||
// stopBtn.disabled = true;
|
||||
// });
|
||||
|
||||
// 开始录音
|
||||
recordBtn.addEventListener('click', async () => {
|
||||
@@ -46,15 +47,29 @@ recordBtn.addEventListener('click', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
mediaRecorder = new MediaRecorder(stream);
|
||||
audioChunks = [];
|
||||
|
||||
mediaRecorder.ondataavailable = (event) => {
|
||||
audioChunks.push(event.data);
|
||||
// 检测浏览器支持的录制格式
|
||||
const getSupportedMimeType = () => {
|
||||
const options = [
|
||||
'audio/webm; codecs=opus',
|
||||
'audio/webm',
|
||||
'audio/mp4',
|
||||
'' // 空字符串表示使用浏览器默认格式
|
||||
];
|
||||
for (const option of options) {
|
||||
if (MediaRecorder.isTypeSupported(option)) return option;
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
|
||||
// 使用检测到的格式初始化
|
||||
mediaRecorder = new MediaRecorder(stream, {
|
||||
mimeType: getSupportedMimeType(),
|
||||
audioBitsPerSecond: 16000
|
||||
});
|
||||
|
||||
// 同时修正Blob类型(确保前后一致)
|
||||
mediaRecorder.onstop = () => {
|
||||
audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
|
||||
audioBlob = new Blob(audioChunks, { type: 'audio/webm' }); // 与录制格式匹配
|
||||
statusDiv.textContent = '录音完成,正在自动提交评测...';
|
||||
submitEvaluation();
|
||||
// 停止所有音轨以释放麦克风
|
||||
@@ -104,11 +119,12 @@ async function submitEvaluation() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!textInput.value.trim()) {
|
||||
statusDiv.textContent = '请输入评测文本内容';
|
||||
statusDiv.className = 'status error';
|
||||
return;
|
||||
}
|
||||
// 移除文本验证
|
||||
// if (!textInput.value.trim()) {
|
||||
// statusDiv.textContent = '请输入评测文本内容';
|
||||
// statusDiv.className = 'status error';
|
||||
// return;
|
||||
// }
|
||||
|
||||
try {
|
||||
statusDiv.textContent = '正在提交评测...';
|
||||
@@ -117,7 +133,8 @@ async function submitEvaluation() {
|
||||
const formData = new FormData();
|
||||
formData.append('audio_file', audioBlob, 'recording.webm');
|
||||
formData.append('language', languageSelect.value);
|
||||
formData.append('text', textInput.value.trim());
|
||||
// 移除文本参数
|
||||
// formData.append('text', textInput.value.trim());
|
||||
formData.append('group', 'adult');
|
||||
formData.append('check_type', 'common');
|
||||
formData.append('grade', 'middle');
|
||||
@@ -168,20 +185,33 @@ function displayResults(results) {
|
||||
if (results.accuracy_score !== undefined) {
|
||||
html += `<p><strong>准确度:</strong> ${results.accuracy_score.toFixed(4)}</p>`;
|
||||
}
|
||||
// 添加结果对象有效性检查
|
||||
if (!results) {
|
||||
showError("评测结果格式错误");
|
||||
return;
|
||||
}
|
||||
|
||||
if (results.fluency_score !== undefined) {
|
||||
html += `<p><strong>流利度:</strong> ${results.fluency_score.toFixed(4)}</p>`;
|
||||
} else {
|
||||
html += `<p><strong>流利度:</strong> 未获取</p>`; // 添加默认值
|
||||
}
|
||||
|
||||
if (results.completeness_score !== undefined) {
|
||||
html += `<p><strong>完整度:</strong> ${results.completeness_score.toFixed(4)}</p>`;
|
||||
} else {
|
||||
html += `<p><strong>完整度:</strong> 未获取</p>`; // 添加默认值
|
||||
}
|
||||
|
||||
|
||||
html += '</div>';
|
||||
|
||||
// 显示单词级评分
|
||||
if (results.words && results.words.length > 0) {
|
||||
html += '<div class="word-scores"><h4>单词评分:</h4><ul>';
|
||||
results.words.forEach(word => {
|
||||
html += `<li>${word.content}: ${word.score.toFixed(4)}</li>`;
|
||||
// 为单词评分添加空值检查
|
||||
const score = word.score !== undefined ? word.score.toFixed(4) : '无';
|
||||
html += `<li>${word.content}: ${score}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
|
Reference in New Issue
Block a user