kemuriririn commited on
Commit
f6fd8f5
·
1 Parent(s): f3cf788

fix syntax

Browse files
Files changed (1) hide show
  1. 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
- // Reference voice preview function
630
- const randomVoiceBtn = document.querySelector('.random-voice-btn');
631
- const voiceFileInput = document.getElementById('voice-file');
632
- const voicePreview = document.getElementById('voice-preview');
633
- if (randomVoiceBtn && voiceFileInput && voicePreview) {
634
- randomVoiceBtn.addEventListener('click', function () {
635
- // 显示加载状态
636
- randomVoiceBtn.classList.add('loading');
637
-
638
- // 获取随机参考音色
639
- fetch('/api/voice/random')
640
- .then(response => {
641
- if (!response.ok) {
642
- throw new Error('获取随机音色失败');
643
- }
644
- return response.blob();
645
- })
646
- .then(audioBlob => {
647
- // 创建文件对象,用于合成时提交
648
- const fileName = 'random_voice_sample.' +
649
- (audioBlob.type.split('/')[1] || 'mp3');
650
-
651
- // 创建File对象,用于后续上传
652
- const audioFile = new File([audioBlob], fileName, {type: audioBlob.type});
653
-
654
- // 创建一个DataTransfer对象来模拟文件输入
655
- const dataTransfer = new DataTransfer();
656
- dataTransfer.items.add(audioFile);
657
- voiceFileInput.files = dataTransfer.files;
658
-
659
- // 更新音频预览
660
- const audioUrl = URL.createObjectURL(audioBlob);
661
- voicePreview.src = audioUrl;
662
- voicePreview.style.display = 'inline-block';
663
- voicePreview.load();
664
- voicePreview.play();
665
-
666
- // 触发change事件,确保其他监听器知道文件已更改
667
- const event = new Event('change', {bubbles: true});
668
- voiceFileInput.dispatchEvent(event);
669
- })
670
- .catch(error => {
671
- console.error('获取随机音色出错:', error);
672
- openToast ? openToast("获取随机参考音色失败", "error") : alert("获取随机参考音色失败");
673
- })
674
- .finally(() => {
675
- // 移除加载状态
676
- randomVoiceBtn.classList.remove('loading');
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