Spaces:
Running
Running
Update index.html
Browse files- index.html +51 -0
index.html
CHANGED
@@ -698,6 +698,41 @@
|
|
698 |
});
|
699 |
}
|
700 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
701 |
// 设置 ASR 事件处理
|
702 |
function setupASREventHandlers(div, entry) {
|
703 |
const startInput = div.querySelector('.start-time');
|
@@ -871,6 +906,22 @@
|
|
871 |
xhr.send();
|
872 |
}
|
873 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
874 |
// 错误处理
|
875 |
function handleUploadError() {
|
876 |
log('Upload error occurred');
|
|
|
698 |
});
|
699 |
}
|
700 |
|
701 |
+
// 导出识别结果为 JSON 或 SRT 格式
|
702 |
+
function exportAsrData(format) {
|
703 |
+
if (asrData.length === 0) {
|
704 |
+
alert('没有数据可以导出');
|
705 |
+
return;
|
706 |
+
}
|
707 |
+
|
708 |
+
// 过滤掉被标记为丢弃的条目
|
709 |
+
const filteredData = asrData.filter(entry => !entry.drop);
|
710 |
+
|
711 |
+
let content = '';
|
712 |
+
if (format === 'json') {
|
713 |
+
content = JSON.stringify(filteredData, null, 2);
|
714 |
+
} else if (format === 'srt') {
|
715 |
+
filteredData.forEach((entry, index) => {
|
716 |
+
content += `${index + 1}\n`;
|
717 |
+
const start = formatTime(entry.start);
|
718 |
+
const end = formatTime(entry.end);
|
719 |
+
content += `${start} --> ${end}\n`;
|
720 |
+
content += `${entry.text}\n${entry.trans}\n\n`;
|
721 |
+
});
|
722 |
+
}
|
723 |
+
|
724 |
+
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
|
725 |
+
const url = URL.createObjectURL(blob);
|
726 |
+
const a = document.createElement('a');
|
727 |
+
a.href = url;
|
728 |
+
a.download = `result.${format}`;
|
729 |
+
document.body.appendChild(a);
|
730 |
+
a.click();
|
731 |
+
document.body.removeChild(a);
|
732 |
+
}
|
733 |
+
|
734 |
+
|
735 |
+
|
736 |
// 设置 ASR 事件处理
|
737 |
function setupASREventHandlers(div, entry) {
|
738 |
const startInput = div.querySelector('.start-time');
|
|
|
906 |
xhr.send();
|
907 |
}
|
908 |
|
909 |
+
// 格式化时间,用于字幕格式化
|
910 |
+
function formatTime(seconds) {
|
911 |
+
const hours = Math.floor(seconds / 3600);
|
912 |
+
const minutes = Math.floor((seconds % 3600) / 60);
|
913 |
+
const secs = Math.floor(seconds % 60);
|
914 |
+
const millis = Math.floor((seconds - Math.floor(seconds)) * 1000);
|
915 |
+
return `${pad(hours)}:${pad(minutes)}:${pad(secs)},${padMillis(millis)}`;
|
916 |
+
}
|
917 |
+
|
918 |
+
function pad(value) {
|
919 |
+
return value.toString().padStart(2, '0');
|
920 |
+
}
|
921 |
+
|
922 |
+
function padMillis(value) {
|
923 |
+
return value.toString().padStart(3, '0');
|
924 |
+
}
|
925 |
// 错误处理
|
926 |
function handleUploadError() {
|
927 |
log('Upload error occurred');
|