kemuriririn commited on
Commit
455b5f2
·
1 Parent(s): 48cff39

update arena page

Browse files
Files changed (1) hide show
  1. templates/arena.html +10 -8
templates/arena.html CHANGED
@@ -27,6 +27,9 @@
27
  <audio id="voice-preview" controls style="display:none;"></audio>
28
  </div>
29
  <hr>
 
 
 
30
  <div class="input-group">
31
  <button type="button" class="segmented-btn random-btn" title="Roll random text">
32
  <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none"
@@ -1012,7 +1015,7 @@
1012
  textInput.value = selectedText;
1013
  textInput.focus();
1014
 
1015
- // 如果页面上没有prompt音频文件,则载入随机的prompt音频
1016
  const voiceFileInput = document.getElementById('voice-file');
1017
  if (voiceFileInput && voiceFileInput.files.length === 0) {
1018
  handleRandomVoice();
@@ -1023,6 +1026,10 @@
1023
  const randomVoiceBtn = document.querySelector('.random-voice-btn');
1024
  const voiceFileInput = document.getElementById('voice-file');
1025
  const voicePreview = document.getElementById('voice-preview');
 
 
 
 
1026
 
1027
  // 显示加载状态
1028
  randomVoiceBtn.classList.add('loading');
@@ -1039,33 +1046,28 @@
1039
  // 创建文件对象,用于合成时提交
1040
  const fileName = 'random_voice_sample.' +
1041
  (audioBlob.type.split('/')[1] || 'mp3');
1042
-
1043
- // 创建File对象,用于后续上传
1044
  const audioFile = new File([audioBlob], fileName, {type: audioBlob.type});
1045
-
1046
- // 创建一个DataTransfer对象来模拟文件输入
1047
  const dataTransfer = new DataTransfer();
1048
  dataTransfer.items.add(audioFile);
1049
  voiceFileInput.files = dataTransfer.files;
1050
-
1051
  // 更新音频预览
1052
  const audioUrl = URL.createObjectURL(audioBlob);
1053
  voicePreview.src = audioUrl;
1054
  voicePreview.style.display = 'inline-block';
1055
  voicePreview.load();
1056
  voicePreview.play();
1057
-
1058
  // 触发change事件,确保其他监听器知道文件已更改
1059
  const event = new Event('change', {bubbles: true});
1060
  voiceFileInput.dispatchEvent(event);
1061
  })
1062
  .catch(error => {
1063
  console.error('获取随机音色出错:', error);
1064
- openToast ? openToast("获取随机参考音色失败", "error") : alert("获取随机参考音色失败");
1065
  })
1066
  .finally(() => {
1067
  // 移除加载状态
1068
  randomVoiceBtn.classList.remove('loading');
 
1069
  });
1070
  }
1071
 
 
27
  <audio id="voice-preview" controls style="display:none;"></audio>
28
  </div>
29
  <hr>
30
+ <div id="random-voice-loading-msg" style="display:none;color:#6658ea;font-size:14px;margin-bottom:8px;">
31
+ Loading random prompt audio...
32
+ </div>
33
  <div class="input-group">
34
  <button type="button" class="segmented-btn random-btn" title="Roll random text">
35
  <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none"
 
1015
  textInput.value = selectedText;
1016
  textInput.focus();
1017
 
1018
+ // 如果页面上没有prompt音频文��,则载入随机的prompt音频
1019
  const voiceFileInput = document.getElementById('voice-file');
1020
  if (voiceFileInput && voiceFileInput.files.length === 0) {
1021
  handleRandomVoice();
 
1026
  const randomVoiceBtn = document.querySelector('.random-voice-btn');
1027
  const voiceFileInput = document.getElementById('voice-file');
1028
  const voicePreview = document.getElementById('voice-preview');
1029
+ const loadingMsg = document.getElementById('random-voice-loading-msg');
1030
+
1031
+ // 显示加载提示
1032
+ if (loadingMsg) loadingMsg.style.display = 'block';
1033
 
1034
  // 显示加载状态
1035
  randomVoiceBtn.classList.add('loading');
 
1046
  // 创建文件对象,用于合成时提交
1047
  const fileName = 'random_voice_sample.' +
1048
  (audioBlob.type.split('/')[1] || 'mp3');
 
 
1049
  const audioFile = new File([audioBlob], fileName, {type: audioBlob.type});
 
 
1050
  const dataTransfer = new DataTransfer();
1051
  dataTransfer.items.add(audioFile);
1052
  voiceFileInput.files = dataTransfer.files;
 
1053
  // 更新音频预览
1054
  const audioUrl = URL.createObjectURL(audioBlob);
1055
  voicePreview.src = audioUrl;
1056
  voicePreview.style.display = 'inline-block';
1057
  voicePreview.load();
1058
  voicePreview.play();
 
1059
  // 触发change事件,确保其他监听器知道文件已更改
1060
  const event = new Event('change', {bubbles: true});
1061
  voiceFileInput.dispatchEvent(event);
1062
  })
1063
  .catch(error => {
1064
  console.error('获取随机音色出错:', error);
1065
+ // 失败时也隐藏提示
1066
  })
1067
  .finally(() => {
1068
  // 移除加载状态
1069
  randomVoiceBtn.classList.remove('loading');
1070
+ if (loadingMsg) loadingMsg.style.display = 'none';
1071
  });
1072
  }
1073