Spaces:
Running
Running
Commit
·
f6fd8f5
1
Parent(s):
f3cf788
fix syntax
Browse files- templates/arena.html +51 -53
templates/arena.html
CHANGED
|
@@ -617,8 +617,6 @@
|
|
| 617 |
}
|
| 618 |
}
|
| 619 |
|
| 620 |
-
}
|
| 621 |
-
|
| 622 |
</style>
|
| 623 |
{% endblock %}
|
| 624 |
|
|
@@ -626,55 +624,56 @@
|
|
| 626 |
<script src="{{ url_for('static', filename='js/waveplayer.js') }}"></script>
|
| 627 |
<script>
|
| 628 |
document.addEventListener('DOMContentLoaded', function () {
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
| 650 |
-
|
| 651 |
-
|
| 652 |
-
|
| 653 |
-
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
|
| 657 |
-
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
|
| 666 |
-
|
| 667 |
-
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
|
| 671 |
-
|
| 672 |
-
|
| 673 |
-
|
| 674 |
-
|
| 675 |
-
|
| 676 |
-
|
| 677 |
-
|
|
|
|
| 678 |
voiceFileInput.addEventListener('change', function () {
|
| 679 |
const file = this.files[0];
|
| 680 |
if (file) {
|
|
@@ -1165,8 +1164,7 @@
|
|
| 1165 |
// Fetch cached sentences when the DOM is ready
|
| 1166 |
fetchCachedSentences();
|
| 1167 |
}
|
| 1168 |
-
)
|
| 1169 |
-
;
|
| 1170 |
</script>
|
| 1171 |
{% endblock %}
|
| 1172 |
|
|
|
|
| 617 |
}
|
| 618 |
}
|
| 619 |
|
|
|
|
|
|
|
| 620 |
</style>
|
| 621 |
{% endblock %}
|
| 622 |
|
|
|
|
| 624 |
<script src="{{ url_for('static', filename='js/waveplayer.js') }}"></script>
|
| 625 |
<script>
|
| 626 |
document.addEventListener('DOMContentLoaded', function () {
|
| 627 |
+
// Reference voice preview function
|
| 628 |
+
const randomVoiceBtn = document.querySelector('.random-voice-btn');
|
| 629 |
+
const voiceFileInput = document.getElementById('voice-file');
|
| 630 |
+
const voicePreview = document.getElementById('voice-preview');
|
| 631 |
+
if (randomVoiceBtn && voiceFileInput && voicePreview) {
|
| 632 |
+
randomVoiceBtn.addEventListener('click', function () {
|
| 633 |
+
// 显示加载状态
|
| 634 |
+
randomVoiceBtn.classList.add('loading');
|
| 635 |
+
|
| 636 |
+
// 获取随机参考音色
|
| 637 |
+
fetch('/api/voice/random')
|
| 638 |
+
.then(response => {
|
| 639 |
+
if (!response.ok) {
|
| 640 |
+
throw new Error('获取随机音色失败');
|
| 641 |
+
}
|
| 642 |
+
return response.blob();
|
| 643 |
+
})
|
| 644 |
+
.then(audioBlob => {
|
| 645 |
+
// 创建文件对象,用于合成时提交
|
| 646 |
+
const fileName = 'random_voice_sample.' +
|
| 647 |
+
(audioBlob.type.split('/')[1] || 'mp3');
|
| 648 |
+
|
| 649 |
+
// 创建File对象,用于后续上传
|
| 650 |
+
const audioFile = new File([audioBlob], fileName, {type: audioBlob.type});
|
| 651 |
+
|
| 652 |
+
// 创建一个DataTransfer对象来模拟文件输入
|
| 653 |
+
const dataTransfer = new DataTransfer();
|
| 654 |
+
dataTransfer.items.add(audioFile);
|
| 655 |
+
voiceFileInput.files = dataTransfer.files;
|
| 656 |
+
|
| 657 |
+
// 更新音频预览
|
| 658 |
+
const audioUrl = URL.createObjectURL(audioBlob);
|
| 659 |
+
voicePreview.src = audioUrl;
|
| 660 |
+
voicePreview.style.display = 'inline-block';
|
| 661 |
+
voicePreview.load();
|
| 662 |
+
voicePreview.play();
|
| 663 |
+
|
| 664 |
+
// 触发change事件,确保其他监听器知道文件已更改
|
| 665 |
+
const event = new Event('change', {bubbles: true});
|
| 666 |
+
voiceFileInput.dispatchEvent(event);
|
| 667 |
+
})
|
| 668 |
+
.catch(error => {
|
| 669 |
+
console.error('获取随机音色出错:', error);
|
| 670 |
+
openToast ? openToast("获取随机参考音色失败", "error") : alert("获取随机参考音色失败");
|
| 671 |
+
})
|
| 672 |
+
.finally(() => {
|
| 673 |
+
// 移除加载状态
|
| 674 |
+
randomVoiceBtn.classList.remove('loading');
|
| 675 |
+
});
|
| 676 |
+
});
|
| 677 |
voiceFileInput.addEventListener('change', function () {
|
| 678 |
const file = this.files[0];
|
| 679 |
if (file) {
|
|
|
|
| 1164 |
// Fetch cached sentences when the DOM is ready
|
| 1165 |
fetchCachedSentences();
|
| 1166 |
}
|
| 1167 |
+
);
|
|
|
|
| 1168 |
</script>
|
| 1169 |
{% endblock %}
|
| 1170 |
|