You can edit the below JavaScript code to customize the image tool.
Apply Changes
function processImage(originalImg, youtubeVideoUrl = "", targetLanguage = "ru-RU") {
// Create the main UI container
const container = document.createElement('div');
container.style.fontFamily = 'system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif';
container.style.maxWidth = '640px';
container.style.margin = '0 auto';
container.style.padding = '24px';
container.style.backgroundColor = '#0f0f0f';
container.style.color = '#f1f1f1';
container.style.borderRadius = '12px';
container.style.boxShadow = '0 10px 30px rgba(0, 0, 0, 0.8)';
container.style.boxSizing = 'border-box';
// Header Title
const title = document.createElement('h2');
title.innerText = 'YouTube Multilingual Auto-Dubbing Tool';
title.style.textAlign = 'center';
title.style.color = '#ff0000';
title.style.marginTop = '0';
title.style.marginBottom = '20px';
title.style.fontWeight = 'bold';
container.appendChild(title);
// Thumbnail Preview (using originalImg as a preview/thumbnail poster)
const previewWrapper = document.createElement('div');
previewWrapper.style.position = 'relative';
previewWrapper.style.width = '100%';
previewWrapper.style.height = '300px';
previewWrapper.style.backgroundColor = '#000000';
previewWrapper.style.borderRadius = '8px';
previewWrapper.style.marginBottom = '24px';
previewWrapper.style.overflow = 'hidden';
previewWrapper.style.display = 'flex';
previewWrapper.style.justifyContent = 'center';
previewWrapper.style.alignItems = 'center';
const bgImage = document.createElement('img');
bgImage.src = originalImg.src;
bgImage.style.width = '100%';
bgImage.style.height = '100%';
bgImage.style.objectFit = 'cover';
bgImage.style.opacity = '0.6';
previewWrapper.appendChild(bgImage);
// Fake video play button
const playBtn = document.createElement('div');
playBtn.innerHTML = `
<svg viewBox="0 0 68 48" width="68" height="48">
<path d="M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z" fill="#ff0000"></path>
<path d="M 45,24 27,14 27,34" fill="#ffffff"></path>
</svg>
`;
playBtn.style.position = 'absolute';
playBtn.style.cursor = 'pointer';
playBtn.style.transition = 'transform 0.2s';
playBtn.onmouseover = () => playBtn.style.transform = 'scale(1.1)';
playBtn.onmouseout = () => playBtn.style.transform = 'scale(1)';
previewWrapper.appendChild(playBtn);
container.appendChild(previewWrapper);
// Form Controls
const formContainer = document.createElement('div');
formContainer.style.display = 'flex';
formContainer.style.flexDirection = 'column';
formContainer.style.gap = '16px';
container.appendChild(formContainer);
// URL Input Field
const urlGroup = document.createElement('div');
urlGroup.style.display = 'flex';
urlGroup.style.flexDirection = 'column';
urlGroup.style.gap = '6px';
const urlLabel = document.createElement('label');
urlLabel.innerText = 'YouTube Video URL:';
urlLabel.style.fontSize = '14px';
urlLabel.style.fontWeight = '500';
urlLabel.style.color = '#aaaaaa';
const urlInput = document.createElement('input');
urlInput.type = 'text';
urlInput.placeholder = 'https://www.youtube.com/watch?v=...';
urlInput.value = youtubeVideoUrl;
urlInput.style.padding = '12px';
urlInput.style.borderRadius = '6px';
urlInput.style.border = '1px solid #333333';
urlInput.style.backgroundColor = '#222222';
urlInput.style.color = '#ffffff';
urlInput.style.fontSize = '15px';
urlInput.style.outline = 'none';
urlInput.onfocus = () => urlInput.style.border = '1px solid #3ea6ff';
urlInput.onblur = () => urlInput.style.border = '1px solid #333333';
urlGroup.appendChild(urlLabel);
urlGroup.appendChild(urlInput);
formContainer.appendChild(urlGroup);
// Language Dropdown
const langGroup = document.createElement('div');
langGroup.style.display = 'flex';
langGroup.style.flexDirection = 'column';
langGroup.style.gap = '6px';
const langLabel = document.createElement('label');
langLabel.innerText = 'Select Dubbing Language:';
langLabel.style.fontSize = '14px';
langLabel.style.fontWeight = '500';
langLabel.style.color = '#aaaaaa';
const langSelect = document.createElement('select');
langSelect.style.padding = '12px';
langSelect.style.borderRadius = '6px';
langSelect.style.border = '1px solid #333333';
langSelect.style.backgroundColor = '#222222';
langSelect.style.color = '#ffffff';
langSelect.style.fontSize = '15px';
langSelect.style.outline = 'none';
// Multi-Language Options
const languages = [
{ code: 'ru-RU', name: 'Russian (Русский)' },
{ code: 'en-US', name: 'English (US)' },
{ code: 'es-ES', name: 'Spanish (Español)' },
{ code: 'fr-FR', name: 'French (Français)' },
{ code: 'de-DE', name: 'German (Deutsch)' },
{ code: 'zh-CN', name: 'Chinese (中文)' },
{ code: 'ja-JP', name: 'Japanese (日本語)' }
];
languages.forEach(lang => {
const option = document.createElement('option');
option.value = lang.code;
option.innerText = lang.name;
if (lang.code === targetLanguage) {
option.selected = true;
}
langSelect.appendChild(option);
});
langGroup.appendChild(langLabel);
langGroup.appendChild(langSelect);
formContainer.appendChild(langGroup);
// Action Button
const processBtn = document.createElement('button');
processBtn.innerText = 'Generate AI Auto-Dub';
processBtn.style.marginTop = '10px';
processBtn.style.padding = '14px';
processBtn.style.backgroundColor = '#f1f1f1';
processBtn.style.color = '#0f0f0f';
processBtn.style.border = 'none';
processBtn.style.borderRadius = '24px';
processBtn.style.fontSize = '16px';
processBtn.style.fontWeight = 'bold';
processBtn.style.cursor = 'pointer';
processBtn.style.transition = 'background-color 0.2s';
processBtn.onmouseover = () => { if (!processBtn.disabled) processBtn.style.backgroundColor = '#d9d9d9'; };
processBtn.onmouseout = () => { if (!processBtn.disabled) processBtn.style.backgroundColor = '#f1f1f1'; };
formContainer.appendChild(processBtn);
// Progress UI Area (Hidden Initially)
const progressArea = document.createElement('div');
progressArea.style.display = 'none';
progressArea.style.flexDirection = 'column';
progressArea.style.gap = '8px';
progressArea.style.marginTop = '20px';
const statusLabel = document.createElement('div');
statusLabel.innerText = 'Initializing...';
statusLabel.style.fontSize = '13px';
statusLabel.style.fontWeight = 'bold';
statusLabel.style.color = '#aaaaaa';
statusLabel.style.textAlign = 'center';
const progressBarWrapper = document.createElement('div');
progressBarWrapper.style.width = '100%';
progressBarWrapper.style.height = '6px';
progressBarWrapper.style.backgroundColor = '#333333';
progressBarWrapper.style.borderRadius = '3px';
progressBarWrapper.style.overflow = 'hidden';
const progressBar = document.createElement('div');
progressBar.style.width = '0%';
progressBar.style.height = '100%';
progressBar.style.backgroundColor = '#3ea6ff';
progressBar.style.transition = 'width 0.4s ease';
progressBarWrapper.appendChild(progressBar);
progressArea.appendChild(statusLabel);
progressArea.appendChild(progressBarWrapper);
container.appendChild(progressArea);
// Pre-load web speech voices to prepare for simulation
if (window.speechSynthesis) {
window.speechSynthesis.getVoices();
window.speechSynthesis.onvoiceschanged = () => window.speechSynthesis.getVoices();
}
// Processing Logic (Simulated for Frontend-Only Limitations)
processBtn.addEventListener('click', () => {
if (!urlInput.value.trim().match(/^https?:\/\//)) {
alert('Please provide a valid YouTube URL first.');
return;
}
// Lock UI
processBtn.disabled = true;
processBtn.style.opacity = '0.5';
processBtn.innerText = 'Processing...';
urlInput.disabled = true;
langSelect.disabled = true;
// Show Progress
progressArea.style.display = 'flex';
progressBar.style.backgroundColor = '#3ea6ff';
let progress = 0;
const stages = [
{ threshold: 10, msg: 'Downloading remote video track...' },
{ threshold: 30, msg: 'Extracting clean audio channel (Vocal isolation)...' },
{ threshold: 50, msg: 'Transcribing Original Audio via Speech-to-Text API...' },
{ threshold: 70, msg: 'Translating transcript to target language...' },
{ threshold: 90, msg: 'Generating AI Voice Dubbing (Text-to-Speech)...' },
{ threshold: 100, msg: 'Synchronizing final video and rendering...' }
];
let stageIndex = 0;
const simInterval = setInterval(() => {
progress += Math.floor(Math.random() * 6) + 1;
if (progress >= 100) progress = 100;
progressBar.style.width = `${progress}%`;
if (stageIndex < stages.length && progress >= stages[stageIndex].threshold) {
statusLabel.innerText = stages[stageIndex].msg;
stageIndex++;
}
if (progress === 100) {
clearInterval(simInterval);
finishDubbing();
}
}, 400);
});
function finishDubbing() {
statusLabel.innerText = 'Auto-Dubbing Successfully Complete!';
statusLabel.style.color = '#00e676';
progressBar.style.backgroundColor = '#00e676';
processBtn.innerText = 'Dubbing Ready - Replay Audio Preview';
processBtn.style.backgroundColor = '#00e676';
processBtn.style.color = '#000000';
processBtn.disabled = false;
processBtn.style.opacity = '1';
urlInput.disabled = false;
langSelect.disabled = false;
// Changing the button functionality to replay preview on click
processBtn.onclick = () => playLocalizedConfirmation(langSelect.value);
// Immediately play the confirmation preview
playLocalizedConfirmation(langSelect.value);
}
// Function to simulate the translated autodu-dub using Web Speech API TTS
function playLocalizedConfirmation(langCode) {
if (!window.speechSynthesis) return;
window.speechSynthesis.cancel(); // Stop current speech
const confirmations = {
'ru-RU': 'Ваше видео с YouTube успешно обработано. Автоматический дубляж готов к просмотру.',
'en-US': 'Your YouTube video was processed successfully. The auto dubbing is ready.',
'es-ES': 'Tu vídeo de YouTube ha sido procesado con éxito. El doblaje automático está listo.',
'fr-FR': 'Votre vidéo YouTube a été traitée avec succès. Le doublage automatique est prêt.',
'de-DE': 'Dein YouTube-Video wurde erfolgreich verarbeitet. Die automatische Synchronisation ist fertig.',
'zh-CN': '您的 YouTube 视频已成功处理。 自动配音已准备就绪。',
'ja-JP': 'YouTube ビデオの処理が完了しました。 自動吹き替えの準備ができました。'
};
const msgText = confirmations[langCode] || confirmations['en-US'];
const utterance = new SpeechSynthesisUtterance(msgText);
utterance.lang = langCode;
utterance.rate = 1.0;
utterance.pitch = 1.0;
// Prioritize native-sounding voices if available
const voices = window.speechSynthesis.getVoices();
const suitableVoice = voices.find(v => v.lang.startsWith(langCode.substring(0, 2)));
if (suitableVoice) {
utterance.voice = suitableVoice;
}
window.speechSynthesis.speak(utterance);
}
return container;
}
Apply Changes