Skip to content

Formerly KrillinAI, VideoTranslation and Dubbing Tool for 120+ Languages. Open-source AI workspace for creators, powered by Codex. Video downloader, video translation, create videos, images, audios, and edits with Agents in one place. For your Social Media like YouTube, TikTok, Instagram, etc.

add upload voice

chenxueshuang5ae2f7e0bc9f
diff --git a/static/index.html b/static/index.html
index a0ff24ad..a11465a5 100644
--- a/static/index.html
+++ b/static/index.html
@@ -12,7 +12,7 @@
min-width: 320px;
min-height: 100vh;
color: #333;
- background: url('/static/background.jpg') no-repeat center center fixed;
+ background: #000 url('/static/background.jpg') no-repeat center center fixed;
background-size: cover;
}
@@ -143,7 +143,7 @@
flex-direction: row;
align-items: center;
justify-content: flex-start;
- width: 50%;
+ width: 100%;
min-height: 42px;
gap: 10px;
}
@@ -167,6 +167,7 @@
margin-right: 10px;
}
.loading {
+ word-break: keep-all;
color: #4caf50;
text-align: center;
}
@@ -198,7 +199,7 @@
<div class="formItem hidden" id="fileInputContainer">
<label for="fileInput">上传本地视频:</label>
- <input style="margin-left: 6px" type="file" id="fileInput" name="fileInput" accept="video/*">
+ <input style="margin-left: 6px" type="file" id="fileInput" name="fileInput" accept="video/*, audio/*">
<p id="uploadStatus" class="loading hidden">正在上传...</p>
</div>
@@ -296,16 +297,19 @@
<option value="2">男声</option>
<option value="1">女声</option>
</select>
+ <span>或</span>
+ <input type="file" id="voiceFileInput" name="voiceFileInput" accept="audio/*">
+ <p id="voiceUploadStatus" class="loading hidden">正在上传...</p>
</div>
<!-- 语气词过滤 -->
- <div class="formGroup" style="width: 100%; justify-content: flex-start;">
+ <div class="formGroup">
<label>语气词过滤:</label>
<input type="checkbox" id="filler-filter-toggle" checked>
</div>
<!-- 词汇替换 -->
- <div class="formGroup" style="width: 100%; justify-content: flex-start; align-items: flex-start;">
+ <div class="formGroup" style="justify-content: flex-start; align-items: flex-start;">
<label style="padding: 10px 0;">词汇替换:</label>
<input style="margin: 14px 10px 14px 4px;" type="checkbox" id="word-replacement-toggle">
<div id="word-replacement-container" style="display: none; padding-top: 6px">
@@ -337,18 +341,14 @@
const urlInput = document.getElementById('urlInput');
const fileInput = document.getElementById('fileInput');
const uploadStatus = document.getElementById('uploadStatus');
+ const voiceFileInput = document.getElementById('voiceFileInput');
+ const voiceUploadStatus = document.getElementById('voiceUploadStatus');
const executeButton = document.getElementById('executeButton');
const taskForm = document.getElementById('taskForm');
const progressSection = document.getElementById('progressSection');
const progressBar = document.getElementById('progressBar');
const downloadLinks = document.getElementById('downloadLinks');
- const API_SUBMIT_URL = "/api/capability/subtitleTask";
- const API_PROGRESS_URL = "/api/capability/subtitleTask";
- const API_UPLOAD_URL = "/api/file";
-
- let uploadedVideoUrl = null; // 存储上传后的视频地址
-
// 获取表单元素
const translationToggle = document.getElementById("translation-toggle");
const translationLanguage = document.getElementById("translation-language");
@@ -360,6 +360,12 @@
const wordReplacementContainer = document.getElementById("word-replacement-container");
const addRowButton = document.getElementById("add-row");
+ const API_SUBMIT_URL = "/api/capability/subtitleTask";
+ const API_PROGRESS_URL = "/api/capability/subtitleTask";
+ const API_UPLOAD_URL = "/api/file";
+
+ let uploadedVideoUrl = null; // 存储上传后的视频地址
+
// 更新状态(启用或禁用表单项)
function updateFormState() {
translationLanguage.disabled = !translationToggle.checked;
@@ -372,6 +378,7 @@
voiceoverToggle.disabled = !translationToggle.checked;
bilingualPosition.disabled = !bilingualToggle.checked;
voiceoverVoice.disabled = !voiceoverToggle.checked;
+ voiceFileInput.disabled = !voiceoverToggle.checked;
wordReplacementContainer.style.display = wordReplacementToggle.checked ? "block" : "none";
}
@@ -426,6 +433,9 @@
if (formData.tts === 1) {
formData.tts_voice_code = +voiceoverVoice.value;
+ if (uploadedAudioUrl) {
+ formData.tts_voice_clone_src_file_url = uploadedAudioUrl;
+ }
}
if (formData.target_lang === 'ro2') {
@@ -500,6 +510,33 @@
}
});
+ // 处理音频上传
+ voiceFileInput.addEventListener('change', async () => {
+ if (voiceFileInput.files.length === 0) return;
+
+ voiceUploadStatus.classList.remove('hidden');
+
+ const file = voiceFileInput.files[0];
+
+ const formData = new FormData();
+ formData.append('file', file);
+
+ try {
+ const response = await fetch(API_UPLOAD_URL, {
+ method: 'POST',
+ body: formData,
+ });
+ if (!response.ok) throw new Error('上传失败');
+ const data = await response.json();
+ uploadedAudioUrl = data.data.file_path; // 获取返回的地址
+ } catch (error) {
+ console.error('视频上传失败:', error);
+ alert('视频上传失败,请重试');
+ } finally {
+ voiceUploadStatus.classList.add('hidden');
+ }
+ });
+
// 点击执行按钮发送任务请求
taskForm.addEventListener('submit', async (event) => {
event.preventDefault();