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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en" class="dark">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Hush AI | Voice Audio Studio</title>
|
| 7 |
+
|
| 8 |
+
<!-- PWA Setup -->
|
| 9 |
+
<script>
|
| 10 |
+
const manifest = {
|
| 11 |
+
name: "Hush AI Studio", short_name: "Hush Pro", start_url: ".", display: "standalone",
|
| 12 |
+
background_color: "#0f172a", theme_color: "#8b5cf6",
|
| 13 |
+
icons: [{ src: "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b5cf6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z'/%3E%3Cpath d='M19 10v2a7 7 0 0 1-14 0v-2'/%3E%3Cline x1='12' x2='12' y1='19' y2='22'/%3E%3C/svg%3E", sizes: "512x512", type: "image/svg+xml" }]
|
| 14 |
+
};
|
| 15 |
+
const manifestLink = document.createElement('link');
|
| 16 |
+
manifestLink.rel = 'manifest'; manifestLink.href = 'data:application/manifest+json;charset=utf-8,' + encodeURIComponent(JSON.stringify(manifest));
|
| 17 |
+
document.head.appendChild(manifestLink);
|
| 18 |
+
if ('serviceWorker' in navigator) {
|
| 19 |
+
const blob = new Blob(["self.addEventListener('install', (e) => self.skipWaiting()); self.addEventListener('activate', (e) => self.clients.claim()); self.addEventListener('fetch', (e) => {});"], { type: 'application/javascript' });
|
| 20 |
+
navigator.serviceWorker.register(URL.createObjectURL(blob)).catch(console.error);
|
| 21 |
+
}
|
| 22 |
+
</script>
|
| 23 |
+
|
| 24 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 25 |
+
<script src="https://unpkg.com/lucide@latest"></script>
|
| 26 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
|
| 27 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/lamejs/1.2.1/lame.min.js"></script>
|
| 28 |
+
|
| 29 |
+
<script>
|
| 30 |
+
// Updated theme colors to a sleek Violet to signify the Hush engine
|
| 31 |
+
tailwind.config = { darkMode: 'class', theme: { extend: { colors: { primary: { 50: '#f5f3ff', 100: '#ede9fe', 500: '#8b5cf6', 600: '#7c3aed', 900: '#4c1d95' } } } } }
|
| 32 |
+
</script>
|
| 33 |
+
<style>
|
| 34 |
+
.drag-active { border-color: #8b5cf6 !important; background-color: rgba(139, 92, 246, 0.1) !important; }
|
| 35 |
+
.hidden { display: none !important; }
|
| 36 |
+
.spinner { animation: spin 1s linear infinite; }
|
| 37 |
+
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
|
| 38 |
+
|
| 39 |
+
/* Global Scrollbars */
|
| 40 |
+
::-webkit-scrollbar { width: 6px; height: 6px; }
|
| 41 |
+
::-webkit-scrollbar-track { background: transparent; }
|
| 42 |
+
::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 4px; }
|
| 43 |
+
.dark ::-webkit-scrollbar-thumb { background: #334155; }
|
| 44 |
+
::-webkit-scrollbar-thumb:hover { background: #64748b; }
|
| 45 |
+
.dark ::-webkit-scrollbar-thumb:hover { background: #475569; }
|
| 46 |
+
|
| 47 |
+
/* Custom Premium Range Sliders */
|
| 48 |
+
input[type=range] { -webkit-appearance: none; background: transparent; }
|
| 49 |
+
input[type=range]::-webkit-slider-runnable-track { height: 6px; border-radius: 8px; background: #cbd5e1; }
|
| 50 |
+
.dark input[type=range]::-webkit-slider-runnable-track { background: #334155; }
|
| 51 |
+
input[type=range]::-webkit-slider-thumb {
|
| 52 |
+
-webkit-appearance: none; height: 18px; width: 18px; border-radius: 50%;
|
| 53 |
+
background: currentColor; margin-top: -6px; cursor: pointer;
|
| 54 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.2); transition: transform 0.1s;
|
| 55 |
+
}
|
| 56 |
+
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.15); }
|
| 57 |
+
|
| 58 |
+
/* Aesthetic Modern Waveform Horizontal Scrollbar */
|
| 59 |
+
#waveform > div::-webkit-scrollbar { height: 6px; }
|
| 60 |
+
#waveform > div::-webkit-scrollbar-track { background: transparent; border-radius: 8px; }
|
| 61 |
+
#waveform > div::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.5); border-radius: 8px; }
|
| 62 |
+
.dark #waveform > div::-webkit-scrollbar-thumb { background: rgba(71, 85, 105, 0.6); }
|
| 63 |
+
#waveform > div::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.8); }
|
| 64 |
+
.dark #waveform > div::-webkit-scrollbar-thumb:hover { background: rgba(71, 85, 105, 0.9); }
|
| 65 |
+
|
| 66 |
+
/* Spectrogram Plugin styling */
|
| 67 |
+
#spectrogram { border-top: 1px solid rgba(148, 163, 184, 0.2); margin-top: 4px; }
|
| 68 |
+
.dark #spectrogram { border-top: 1px solid rgba(51, 65, 85, 0.5); }
|
| 69 |
+
</style>
|
| 70 |
+
</head>
|
| 71 |
+
<body class="bg-slate-50 dark:bg-slate-900 text-slate-800 dark:text-slate-200 min-h-screen font-sans selection:bg-primary-500 selection:text-white pb-12 overflow-x-hidden transition-colors duration-200">
|
| 72 |
+
|
| 73 |
+
<audio id="ws-audio" class="hidden" crossorigin="anonymous"></audio>
|
| 74 |
+
|
| 75 |
+
<div class="max-w-7xl mx-auto px-4 pt-8">
|
| 76 |
+
|
| 77 |
+
<header class="flex flex-col md:flex-row items-center justify-between mb-6 gap-4 pb-4">
|
| 78 |
+
<div class="flex items-center gap-4">
|
| 79 |
+
<div class="inline-flex items-center justify-center p-3 bg-white dark:bg-primary-900/50 rounded-2xl border border-slate-200 dark:border-primary-500/30 text-primary-600 dark:text-primary-500 shadow-[0_0_15px_rgba(139,92,246,0.2)]">
|
| 80 |
+
<i data-lucide="mic-off" class="w-6 h-6"></i>
|
| 81 |
+
<i data-lucide="sparkles" class="w-4 h-4 absolute transform translate-x-3 -translate-y-3 text-yellow-500 dark:text-yellow-400"></i>
|
| 82 |
+
</div>
|
| 83 |
+
<div>
|
| 84 |
+
<h1 class="text-3xl font-bold text-slate-900 dark:text-white tracking-tight">Hush AI Studio</h1>
|
| 85 |
+
<p class="text-slate-500 dark:text-slate-400 text-sm flex items-center gap-1">
|
| 86 |
+
<i data-lucide="shield-check" class="w-3 h-3 text-emerald-500 dark:text-green-400"></i> Local 16kHz Background Speaker Suppression
|
| 87 |
+
</p>
|
| 88 |
+
</div>
|
| 89 |
+
</div>
|
| 90 |
+
|
| 91 |
+
<div class="flex items-center gap-4 flex-wrap justify-center">
|
| 92 |
+
<label class="flex items-center gap-2 cursor-pointer group bg-white dark:bg-slate-800 px-3 py-1.5 rounded-lg border border-slate-200 dark:border-slate-700 shadow-sm transition-colors duration-200" title="Processes Left and Right channels independently">
|
| 93 |
+
<input type="checkbox" id="stereoCheck" class="w-4 h-4 rounded border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-700 text-primary-500 focus:ring-primary-500 cursor-pointer">
|
| 94 |
+
<span class="text-sm font-medium text-slate-600 dark:text-slate-300 group-hover:text-slate-900 dark:group-hover:text-white transition-colors">Preserve Stereo</span>
|
| 95 |
+
</label>
|
| 96 |
+
|
| 97 |
+
<label class="flex items-center gap-2 cursor-pointer group bg-white dark:bg-slate-800 px-3 py-1.5 rounded-lg border border-slate-200 dark:border-slate-700 shadow-sm transition-colors duration-200">
|
| 98 |
+
<input type="checkbox" id="normalizeCheck" checked class="w-4 h-4 rounded border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-700 text-primary-500 focus:ring-primary-500 cursor-pointer">
|
| 99 |
+
<span class="text-sm font-medium text-slate-600 dark:text-slate-300 group-hover:text-slate-900 dark:group-hover:text-white transition-colors">Auto-Normalize</span>
|
| 100 |
+
</label>
|
| 101 |
+
|
| 102 |
+
<div class="flex items-center bg-slate-100 dark:bg-slate-900 rounded-lg p-1 border border-slate-200 dark:border-slate-700 shadow-sm transition-colors duration-200">
|
| 103 |
+
<button id="formatWav" class="px-3 py-1.5 text-xs font-bold rounded-md text-slate-500 dark:text-slate-400 hover:text-slate-800 dark:hover:text-white transition-all">WAV</button>
|
| 104 |
+
<button id="formatMp3" class="px-3 py-1.5 text-xs font-bold rounded-md bg-primary-600 text-white transition-all shadow-sm">MP3</button>
|
| 105 |
+
</div>
|
| 106 |
+
|
| 107 |
+
<button id="themeToggle" class="p-2 rounded-xl bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 text-slate-500 dark:text-slate-400 hover:text-primary-500 transition-colors shadow-sm">
|
| 108 |
+
<i data-lucide="sun" class="w-5 h-5 hidden dark:block text-yellow-400"></i>
|
| 109 |
+
<i data-lucide="moon" class="w-5 h-5 block dark:hidden"></i>
|
| 110 |
+
</button>
|
| 111 |
+
</div>
|
| 112 |
+
</header>
|
| 113 |
+
|
| 114 |
+
<!-- Aesthetic Pro Controls Dashboard -->
|
| 115 |
+
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
|
| 116 |
+
<!-- Noise Reduction -->
|
| 117 |
+
<div class="bg-white dark:bg-slate-800/80 p-5 rounded-xl border border-slate-200 dark:border-slate-700 shadow-sm hover:shadow-md transition-shadow duration-200 flex flex-col gap-4">
|
| 118 |
+
<div class="flex justify-between items-center">
|
| 119 |
+
<label class="text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-wider flex items-center gap-2"><i data-lucide="cpu" class="w-4 h-4 text-primary-500"></i> Hush Intensity</label>
|
| 120 |
+
<div class="flex items-center gap-1.5">
|
| 121 |
+
<button id="resetNoise" title="Reset to Default" class="p-1 text-slate-400 hover:text-primary-500 dark:hover:text-primary-400 transition-colors opacity-60 hover:opacity-100 rounded-full hover:bg-slate-100 dark:hover:bg-slate-700/50"><i data-lucide="rotate-ccw" class="w-3 h-3"></i></button>
|
| 122 |
+
<span id="noiseLevelValue" class="text-sm text-primary-600 dark:text-primary-400 font-bold bg-primary-50 dark:bg-primary-900/30 px-2 py-0.5 rounded border border-primary-100 dark:border-primary-800/50">100%</span>
|
| 123 |
+
</div>
|
| 124 |
+
</div>
|
| 125 |
+
<input type="range" id="noiseLevel" min="0" max="100" value="100" class="w-full text-primary-500">
|
| 126 |
+
</div>
|
| 127 |
+
|
| 128 |
+
<!-- Bass EQ -->
|
| 129 |
+
<div class="bg-white dark:bg-slate-800/80 p-5 rounded-xl border border-slate-200 dark:border-slate-700 shadow-sm hover:shadow-md transition-shadow duration-200 flex flex-col gap-4">
|
| 130 |
+
<div class="flex justify-between items-center">
|
| 131 |
+
<label class="text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-wider flex items-center gap-2"><i data-lucide="speaker" class="w-4 h-4 text-emerald-500"></i> Bass EQ</label>
|
| 132 |
+
<div class="flex items-center gap-1.5">
|
| 133 |
+
<button id="resetBass" title="Reset to 0dB" class="p-1 text-slate-400 hover:text-emerald-500 dark:hover:text-emerald-400 transition-colors opacity-60 hover:opacity-100 rounded-full hover:bg-slate-100 dark:hover:bg-slate-700/50"><i data-lucide="rotate-ccw" class="w-3 h-3"></i></button>
|
| 134 |
+
<span id="bassVal" class="text-sm text-emerald-600 dark:text-emerald-400 font-bold bg-emerald-50 dark:bg-emerald-900/30 px-2 py-0.5 rounded border border-emerald-100 dark:border-emerald-800/50">0dB</span>
|
| 135 |
+
</div>
|
| 136 |
+
</div>
|
| 137 |
+
<input type="range" id="eqBass" min="-12" max="12" value="0" step="0.5" class="w-full text-emerald-500">
|
| 138 |
+
</div>
|
| 139 |
+
|
| 140 |
+
<!-- Treble EQ -->
|
| 141 |
+
<div class="bg-white dark:bg-slate-800/80 p-5 rounded-xl border border-slate-200 dark:border-slate-700 shadow-sm hover:shadow-md transition-shadow duration-200 flex flex-col gap-4">
|
| 142 |
+
<div class="flex justify-between items-center">
|
| 143 |
+
<label class="text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-wider flex items-center gap-2"><i data-lucide="audio-waveform" class="w-4 h-4 text-amber-500"></i> Treble EQ</label>
|
| 144 |
+
<div class="flex items-center gap-1.5">
|
| 145 |
+
<button id="resetTreble" title="Reset to 0dB" class="p-1 text-slate-400 hover:text-amber-500 dark:hover:text-amber-400 transition-colors opacity-60 hover:opacity-100 rounded-full hover:bg-slate-100 dark:hover:bg-slate-700/50"><i data-lucide="rotate-ccw" class="w-3 h-3"></i></button>
|
| 146 |
+
<span id="trebleVal" class="text-sm text-amber-600 dark:text-amber-400 font-bold bg-amber-50 dark:bg-amber-900/30 px-2 py-0.5 rounded border border-amber-100 dark:border-amber-800/50">0dB</span>
|
| 147 |
+
</div>
|
| 148 |
+
</div>
|
| 149 |
+
<input type="range" id="eqTreble" min="-12" max="12" value="0" step="0.5" class="w-full text-amber-500">
|
| 150 |
+
</div>
|
| 151 |
+
|
| 152 |
+
<!-- Output Gain -->
|
| 153 |
+
<div class="bg-white dark:bg-slate-800/80 p-5 rounded-xl border border-slate-200 dark:border-slate-700 shadow-sm hover:shadow-md transition-shadow duration-200 flex flex-col gap-4">
|
| 154 |
+
<div class="flex justify-between items-center">
|
| 155 |
+
<label class="text-xs font-bold text-slate-500 dark:text-slate-400 uppercase tracking-wider flex items-center gap-2"><i data-lucide="volume-2" class="w-4 h-4 text-rose-500"></i> Output Gain</label>
|
| 156 |
+
<div class="flex items-center gap-1.5">
|
| 157 |
+
<button id="resetGain" title="Reset to 0dB" class="p-1 text-slate-400 hover:text-rose-500 dark:hover:text-rose-400 transition-colors opacity-60 hover:opacity-100 rounded-full hover:bg-slate-100 dark:hover:bg-slate-700/50"><i data-lucide="rotate-ccw" class="w-3 h-3"></i></button>
|
| 158 |
+
<span id="gainVal" class="text-sm text-rose-600 dark:text-rose-400 font-bold bg-rose-50 dark:bg-rose-900/30 px-2 py-0.5 rounded border border-rose-100 dark:border-rose-800/50">0dB</span>
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
<input type="range" id="eqGain" min="-12" max="12" value="0" step="0.5" class="w-full text-rose-500">
|
| 162 |
+
</div>
|
| 163 |
+
</div>
|
| 164 |
+
|
| 165 |
+
<main class="grid lg:grid-cols-[300px_1fr] gap-6">
|
| 166 |
+
<!-- Sidebar: Upload & Queue -->
|
| 167 |
+
<aside class="flex flex-col gap-4">
|
| 168 |
+
<div class="flex flex-col gap-2">
|
| 169 |
+
<div id="dropzone" class="bg-white dark:bg-transparent border-2 border-dashed border-slate-300 dark:border-slate-600 rounded-2xl p-6 text-center cursor-pointer transition-all duration-200 hover:border-primary-500 dark:hover:border-primary-500 dark:hover:bg-slate-800/80 group">
|
| 170 |
+
<input type="file" id="fileInput" accept="audio/*" multiple class="hidden">
|
| 171 |
+
<i data-lucide="file-audio" id="dropzoneIcon" class="w-8 h-8 mx-auto text-slate-400 group-hover:text-primary-500 transition-colors mb-2"></i>
|
| 172 |
+
<h3 class="font-semibold text-slate-700 dark:text-white text-sm">Add Audio Files</h3>
|
| 173 |
+
<p class="text-slate-500 text-xs mt-1">Drag & Drop or Click</p>
|
| 174 |
+
</div>
|
| 175 |
+
|
| 176 |
+
<div id="dropzoneActions" class="hidden flex justify-between items-center px-2 transition-all duration-200">
|
| 177 |
+
<span class="text-xs text-emerald-600 dark:text-emerald-400 font-medium flex items-center gap-1"><i data-lucide="check-circle-2" class="w-3 h-3"></i> <span id="dropzoneIndicatorText">Audio added</span></span>
|
| 178 |
+
<button id="clearAllBtn" class="text-xs text-red-500 hover:text-red-600 dark:hover:text-red-400 font-medium flex items-center gap-1 transition-colors cursor-pointer z-10"><i data-lucide="trash-2" class="w-3 h-3"></i> Clear All</button>
|
| 179 |
+
</div>
|
| 180 |
+
</div>
|
| 181 |
+
|
| 182 |
+
<div class="bg-white dark:bg-slate-800 rounded-2xl border border-slate-200 dark:border-slate-700 flex-1 flex flex-col overflow-hidden max-h-[600px] shadow-sm">
|
| 183 |
+
<div class="p-4 border-b border-slate-200 dark:border-slate-700 flex justify-between items-center bg-slate-50 dark:bg-slate-800/90">
|
| 184 |
+
<h3 class="font-semibold text-slate-800 dark:text-white flex items-center gap-2"><i data-lucide="list-video" class="w-4 h-4 text-slate-500"></i> Batch Queue</h3>
|
| 185 |
+
<span id="queueCount" class="bg-slate-200 dark:bg-slate-700 text-xs px-2 py-0.5 rounded-full text-slate-600 dark:text-slate-300 font-medium">0 files</span>
|
| 186 |
+
</div>
|
| 187 |
+
<div id="fileList" class="overflow-y-auto flex-1 p-2 space-y-1">
|
| 188 |
+
<div class="p-4 text-center text-slate-400 dark:text-slate-500 text-sm italic empty-state">Queue is empty.</div>
|
| 189 |
+
</div>
|
| 190 |
+
|
| 191 |
+
<div class="p-4 border-t border-slate-200 dark:border-slate-700 bg-slate-50 dark:bg-slate-800/90 space-y-3">
|
| 192 |
+
<!-- Dynamic Process Button -->
|
| 193 |
+
<button id="processBtn" disabled class="w-full flex items-center justify-center gap-2 bg-primary-600 disabled:bg-slate-200 dark:disabled:bg-slate-700 disabled:text-slate-400 dark:disabled:text-slate-500 hover:bg-primary-500 text-white px-4 py-2.5 rounded-xl font-medium transition-all shadow-sm disabled:shadow-none">
|
| 194 |
+
<i data-lucide="cpu" class="w-4 h-4"></i> Process
|
| 195 |
+
</button>
|
| 196 |
+
<button id="downloadZipBtn" class="hidden w-full flex items-center justify-center gap-2 bg-emerald-600 hover:bg-emerald-500 text-white px-4 py-2.5 rounded-xl font-medium transition-all shadow-[0_0_15px_rgba(16,185,129,0.2)]">
|
| 197 |
+
<i data-lucide="archive" class="w-4 h-4"></i> Download ZIP
|
| 198 |
+
</button>
|
| 199 |
+
</div>
|
| 200 |
+
</div>
|
| 201 |
+
|
| 202 |
+
<p class="text-[10px] text-center text-slate-400 dark:text-slate-500 font-mono mt-[-5px]">
|
| 203 |
+
Shortcuts: [Space] Play, [←/→] Seek, [Del] Remove
|
| 204 |
+
</p>
|
| 205 |
+
</aside>
|
| 206 |
+
|
| 207 |
+
<!-- Main Workspace -->
|
| 208 |
+
<section class="bg-white dark:bg-slate-800 rounded-2xl border border-slate-200 dark:border-slate-700 flex flex-col overflow-hidden min-h-[400px] shadow-sm">
|
| 209 |
+
|
| 210 |
+
<div id="workspaceEmpty" class="flex-1 flex flex-col items-center justify-center text-slate-400 dark:text-slate-500 p-10">
|
| 211 |
+
<i data-lucide="activity" class="w-16 h-16 text-slate-300 dark:text-slate-700 mb-4"></i>
|
| 212 |
+
<p class="text-lg text-slate-500 dark:text-slate-400">Select a file from the queue to edit</p>
|
| 213 |
+
</div>
|
| 214 |
+
|
| 215 |
+
<div id="workspaceActive" class="hidden flex-1 flex flex-col">
|
| 216 |
+
<!-- File Header & Playback Modes -->
|
| 217 |
+
<div class="p-5 border-b border-slate-200 dark:border-slate-700 flex justify-between items-center bg-slate-50 dark:bg-slate-900/40">
|
| 218 |
+
<h2 id="activeFileName" class="text-xl font-bold text-slate-800 dark:text-white truncate max-w-[50%]">filename.wav</h2>
|
| 219 |
+
|
| 220 |
+
<!-- Toggle modes: Original | Preview (Realtime AI) | Processed -->
|
| 221 |
+
<div id="abToggleContainer" class="bg-slate-200 dark:bg-slate-900 p-1 rounded-lg border border-slate-300 dark:border-slate-700 flex items-center shadow-inner">
|
| 222 |
+
<button id="btnOriginal" class="px-4 py-1.5 text-xs font-bold rounded-md bg-white dark:bg-slate-700 text-slate-800 dark:text-white transition-all shadow-sm">Original</button>
|
| 223 |
+
<button id="btnPreview" class="px-4 py-1.5 text-xs font-bold rounded-md text-slate-500 dark:text-slate-400 hover:text-slate-800 dark:hover:text-white transition-all" title="Hear AI noise reduction applied in real-time">Live Preview</button>
|
| 224 |
+
<button id="btnCleaned" disabled class="px-4 py-1.5 text-xs font-bold rounded-md text-slate-400 dark:text-slate-600 cursor-not-allowed transition-all" title="Must Process first to unlock the final baked file">Processed</button>
|
| 225 |
+
</div>
|
| 226 |
+
</div>
|
| 227 |
+
|
| 228 |
+
<!-- Waveform & Spectrogram Area with Zoom -->
|
| 229 |
+
<div class="flex-1 flex flex-col justify-center p-6 bg-slate-50 dark:bg-slate-900/20 relative">
|
| 230 |
+
<div class="absolute top-4 right-6 flex items-center gap-2 bg-white/90 dark:bg-slate-900/80 px-2 py-1.5 rounded-lg border border-slate-200 dark:border-slate-700 z-10 shadow-sm backdrop-blur">
|
| 231 |
+
<i data-lucide="zoom-out" class="w-3 h-3 text-slate-400 dark:text-slate-500"></i>
|
| 232 |
+
<input type="range" id="zoomSlider" min="0" max="200" value="0" title="Adjust Zoom (0 = Fit)" class="w-24 accent-primary-500 h-1 bg-slate-200 dark:bg-slate-700 rounded-lg cursor-pointer">
|
| 233 |
+
<i data-lucide="zoom-in" class="w-3 h-3 text-slate-400 dark:text-slate-500"></i>
|
| 234 |
+
</div>
|
| 235 |
+
|
| 236 |
+
<!-- Visualization Container -->
|
| 237 |
+
<div class="w-full relative">
|
| 238 |
+
<div id="waveform"></div>
|
| 239 |
+
<div id="spectrogram"></div>
|
| 240 |
+
</div>
|
| 241 |
+
|
| 242 |
+
<div id="timeDisplay" class="absolute bottom-4 right-6 text-xs font-mono text-slate-500 dark:text-slate-400 bg-white/90 dark:bg-slate-900/80 px-2 py-1 rounded shadow-sm border border-slate-200 dark:border-slate-700 z-10">00:00 / 00:00</div>
|
| 243 |
+
</div>
|
| 244 |
+
|
| 245 |
+
<!-- Trimming & Controls -->
|
| 246 |
+
<div class="p-5 border-t border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800/80">
|
| 247 |
+
<div class="flex flex-col md:flex-row gap-6 items-center justify-between">
|
| 248 |
+
|
| 249 |
+
<!-- Playback -->
|
| 250 |
+
<div class="flex items-center gap-3">
|
| 251 |
+
<button id="playBtn" class="w-14 h-14 flex items-center justify-center bg-primary-600 hover:bg-primary-500 text-white rounded-full transition-all shadow-lg hover:scale-105">
|
| 252 |
+
<span id="iconPlayWrap" class="flex items-center justify-center ml-1"><i data-lucide="play" class="w-6 h-6 fill-current"></i></span>
|
| 253 |
+
<span id="iconPauseWrap" class="hidden items-center justify-center"><i data-lucide="pause" class="w-6 h-6 fill-current"></i></span>
|
| 254 |
+
</button>
|
| 255 |
+
</div>
|
| 256 |
+
|
| 257 |
+
<!-- Trimming -->
|
| 258 |
+
<div class="flex items-center gap-2 flex-1 max-w-xl">
|
| 259 |
+
<i data-lucide="scissors" class="w-4 h-4 text-slate-400 dark:text-slate-500"></i>
|
| 260 |
+
<div class="flex items-center gap-2 bg-slate-50 dark:bg-slate-900 p-2 rounded-lg border border-slate-200 dark:border-slate-700 flex-1">
|
| 261 |
+
<div class="flex-1 flex flex-col">
|
| 262 |
+
<label class="text-[10px] font-semibold text-slate-500 uppercase ml-1">Start (sec)</label>
|
| 263 |
+
<div class="flex gap-1 mt-0.5">
|
| 264 |
+
<input type="number" id="trimStart" step="0.1" min="0" value="0.0" class="w-full bg-white dark:bg-slate-800 text-slate-900 dark:text-white text-sm px-2 py-1 rounded border border-slate-200 dark:border-slate-600 focus:border-primary-500 outline-none font-mono">
|
| 265 |
+
<button id="setStartBtn" title="Set to current playhead" class="px-2 bg-slate-200 dark:bg-slate-700 hover:bg-slate-300 dark:hover:bg-slate-600 rounded text-slate-600 dark:text-slate-300 transition-colors"><i data-lucide="map-pin" class="w-3 h-3"></i></button>
|
| 266 |
+
</div>
|
| 267 |
+
</div>
|
| 268 |
+
<div class="w-4 border-t border-slate-300 dark:border-slate-600"></div>
|
| 269 |
+
<div class="flex-1 flex flex-col">
|
| 270 |
+
<label class="text-[10px] font-semibold text-slate-500 uppercase ml-1">End (sec)</label>
|
| 271 |
+
<div class="flex gap-1 mt-0.5">
|
| 272 |
+
<input type="number" id="trimEnd" step="0.1" min="0" value="0.0" class="w-full bg-white dark:bg-slate-800 text-slate-900 dark:text-white text-sm px-2 py-1 rounded border border-slate-200 dark:border-slate-600 focus:border-primary-500 outline-none font-mono">
|
| 273 |
+
<button id="setEndBtn" title="Set to current playhead" class="px-2 bg-slate-200 dark:bg-slate-700 hover:bg-slate-300 dark:hover:bg-slate-600 rounded text-slate-600 dark:text-slate-300 transition-colors"><i data-lucide="map-pin" class="w-3 h-3"></i></button>
|
| 274 |
+
</div>
|
| 275 |
+
</div>
|
| 276 |
+
</div>
|
| 277 |
+
</div>
|
| 278 |
+
|
| 279 |
+
<!-- Download Single -->
|
| 280 |
+
<div>
|
| 281 |
+
<button id="downloadSingleBtn" class="hidden flex items-center gap-2 bg-slate-200 dark:bg-slate-700 hover:bg-slate-300 dark:hover:bg-slate-600 text-slate-800 dark:text-white px-4 py-3 rounded-lg text-sm font-medium transition-all border border-slate-300 dark:border-transparent">
|
| 282 |
+
<i data-lucide="download" class="w-4 h-4"></i> Save
|
| 283 |
+
</button>
|
| 284 |
+
</div>
|
| 285 |
+
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
|
| 290 |
+
</section>
|
| 291 |
+
</main>
|
| 292 |
+
</div>
|
| 293 |
+
|
| 294 |
+
<!-- Web Modules -->
|
| 295 |
+
<script type="module">
|
| 296 |
+
import WaveSurfer from 'https://unpkg.com/wavesurfer.js@7/dist/wavesurfer.esm.js';
|
| 297 |
+
import Spectrogram from 'https://unpkg.com/wavesurfer.js@7/dist/plugins/spectrogram.esm.js';
|
| 298 |
+
|
| 299 |
+
// --- HUGGING FACE DIRECT FETCH INTERCEPTOR FOR HUSH INTEGRATION ---
|
| 300 |
+
if (typeof window.SharedArrayBuffer === 'undefined') { window.SharedArrayBuffer = window.ArrayBuffer; }
|
| 301 |
+
const originalFetch = window.fetch;
|
| 302 |
+
window.fetch = async function(...args) {
|
| 303 |
+
let request = args[0];
|
| 304 |
+
let reqUrl = typeof request === 'string' ? request : (request && request.url);
|
| 305 |
+
if (reqUrl && typeof reqUrl === 'string') {
|
| 306 |
+
let newUrl = null;
|
| 307 |
+
// Keep WASM engine identical but substitute the DeepFilterNet ONNX with the Hush ONNX Model
|
| 308 |
+
if (reqUrl.includes('df_bg.wasm')) newUrl = 'https://huggingface.co/trysem/DeepFilterNet3/resolve/main/df_bg.wasm';
|
| 309 |
+
else if (reqUrl.includes('DeepFilterNet3_onnx.tar.gz')) newUrl = 'https://huggingface.co/weya-ai/hush/resolve/main/onnx/advanced_dfnet16k_model_best_onnx.tar.gz';
|
| 310 |
+
if (newUrl) args[0] = request instanceof Request ? new Request(newUrl, request) : newUrl;
|
| 311 |
+
}
|
| 312 |
+
return originalFetch.apply(this, args);
|
| 313 |
+
};
|
| 314 |
+
|
| 315 |
+
// --- STATE MANAGEMENT ---
|
| 316 |
+
const state = {
|
| 317 |
+
files: [], activeId: null,
|
| 318 |
+
settings: { format: 'mp3', normalize: true, stereo: false, noiseLevel: 100, bass: 0, treble: 0, gain: 0 },
|
| 319 |
+
|
| 320 |
+
ProcessorClass: null,
|
| 321 |
+
assetConfigObj: {
|
| 322 |
+
cdnUrl: 'https://huggingface.co/weya-ai/hush/resolve/main/onnx',
|
| 323 |
+
modelUrl: 'https://huggingface.co/weya-ai/hush/resolve/main/onnx/advanced_dfnet16k_model_best_onnx.tar.gz',
|
| 324 |
+
wasmUrl: 'https://huggingface.co/trysem/DeepFilterNet3/resolve/main/df_bg.wasm'
|
| 325 |
+
},
|
| 326 |
+
|
| 327 |
+
dfNetProc: null, wavesurfer: null, playbackMode: 'original',
|
| 328 |
+
liveCtx: null, mediaNode: null, liveNodes: {}
|
| 329 |
+
};
|
| 330 |
+
|
| 331 |
+
// --- UI BINDINGS ---
|
| 332 |
+
lucide.createIcons();
|
| 333 |
+
const UI = {
|
| 334 |
+
dropzone: document.getElementById('dropzone'), fileInput: document.getElementById('fileInput'),
|
| 335 |
+
dropzoneActions: document.getElementById('dropzoneActions'), dropzoneIndicatorText: document.getElementById('dropzoneIndicatorText'),
|
| 336 |
+
clearAllBtn: document.getElementById('clearAllBtn'), dropzoneIcon: document.getElementById('dropzoneIcon'),
|
| 337 |
+
fileList: document.getElementById('fileList'), queueCount: document.getElementById('queueCount'),
|
| 338 |
+
processBtn: document.getElementById('processBtn'), downloadZipBtn: document.getElementById('downloadZipBtn'),
|
| 339 |
+
workspaceEmpty: document.getElementById('workspaceEmpty'), workspaceActive: document.getElementById('workspaceActive'),
|
| 340 |
+
activeFileName: document.getElementById('activeFileName'), playBtn: document.getElementById('playBtn'),
|
| 341 |
+
iconPlayWrap: document.getElementById('iconPlayWrap'), iconPauseWrap: document.getElementById('iconPauseWrap'),
|
| 342 |
+
timeDisplay: document.getElementById('timeDisplay'), trimStart: document.getElementById('trimStart'),
|
| 343 |
+
trimEnd: document.getElementById('trimEnd'), btnOriginal: document.getElementById('btnOriginal'),
|
| 344 |
+
btnPreview: document.getElementById('btnPreview'), btnCleaned: document.getElementById('btnCleaned'),
|
| 345 |
+
downloadSingleBtn: document.getElementById('downloadSingleBtn'), themeToggle: document.getElementById('themeToggle'),
|
| 346 |
+
zoomSlider: document.getElementById('zoomSlider')
|
| 347 |
+
};
|
| 348 |
+
|
| 349 |
+
// Handles Process Button UI States natively
|
| 350 |
+
function updateProcessButtonText() {
|
| 351 |
+
const count = state.files.length;
|
| 352 |
+
if (count === 0) {
|
| 353 |
+
UI.processBtn.innerHTML = `<i data-lucide="cpu" class="w-4 h-4"></i> Process`;
|
| 354 |
+
UI.processBtn.disabled = true;
|
| 355 |
+
} else if (count === 1) {
|
| 356 |
+
UI.processBtn.innerHTML = `<i data-lucide="cpu" class="w-4 h-4"></i> Process`;
|
| 357 |
+
UI.processBtn.disabled = false;
|
| 358 |
+
} else {
|
| 359 |
+
UI.processBtn.innerHTML = `<i data-lucide="cpu" class="w-4 h-4"></i> Start Batch Processing`;
|
| 360 |
+
UI.processBtn.disabled = false;
|
| 361 |
+
}
|
| 362 |
+
lucide.createIcons();
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
function setProcessButtonState(isProcessing, progressStr = '') {
|
| 366 |
+
if (isProcessing) {
|
| 367 |
+
UI.processBtn.disabled = true;
|
| 368 |
+
UI.processBtn.innerHTML = `<i data-lucide="loader-2" class="w-4 h-4 spinner"></i> ${progressStr}`;
|
| 369 |
+
} else {
|
| 370 |
+
updateProcessButtonText();
|
| 371 |
+
}
|
| 372 |
+
lucide.createIcons();
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
// --- PRE-LOAD AI MODEL ON STARTUP ---
|
| 376 |
+
window.addEventListener('DOMContentLoaded', async () => {
|
| 377 |
+
setProcessButtonState(true, "Loading Hush AI...");
|
| 378 |
+
try {
|
| 379 |
+
const dfModule = await import('https://esm.sh/deepfilternet3-noise-filter@1.2.1');
|
| 380 |
+
state.ProcessorClass = dfModule.DeepFilterNet3Core || dfModule.DeepFilterNoiseFilterProcessor;
|
| 381 |
+
|
| 382 |
+
// MIGRATION: Hush is strictly a 16kHz model
|
| 383 |
+
state.dfNetProc = new state.ProcessorClass({
|
| 384 |
+
sampleRate: 16000, noiseReductionLevel: state.settings.noiseLevel, assetConfig: state.assetConfigObj
|
| 385 |
+
});
|
| 386 |
+
|
| 387 |
+
await state.dfNetProc.initialize();
|
| 388 |
+
setProcessButtonState(false);
|
| 389 |
+
} catch (err) {
|
| 390 |
+
console.error(err);
|
| 391 |
+
UI.processBtn.innerHTML = `<i data-lucide="alert-triangle" class="w-4 h-4"></i> AI Error`;
|
| 392 |
+
lucide.createIcons();
|
| 393 |
+
}
|
| 394 |
+
});
|
| 395 |
+
|
| 396 |
+
// --- THEME & SETTINGS LOGIC ---
|
| 397 |
+
UI.themeToggle.onclick = () => { document.documentElement.classList.toggle('dark'); };
|
| 398 |
+
|
| 399 |
+
document.getElementById('stereoCheck').addEventListener('change', (e) => state.settings.stereo = e.target.checked);
|
| 400 |
+
document.getElementById('normalizeCheck').addEventListener('change', (e) => state.settings.normalize = e.target.checked);
|
| 401 |
+
|
| 402 |
+
const updateEqLabel = (id, val) => { const v = parseFloat(val); document.getElementById(id).textContent = (v > 0 ? '+' : '') + v + 'dB'; };
|
| 403 |
+
|
| 404 |
+
// Slider Logic
|
| 405 |
+
document.getElementById('noiseLevel').addEventListener('input', (e) => {
|
| 406 |
+
state.settings.noiseLevel = parseInt(e.target.value, 10);
|
| 407 |
+
document.getElementById('noiseLevelValue').textContent = e.target.value + '%';
|
| 408 |
+
if (state.dfNetProc && state.liveCtx) state.dfNetProc.noiseReductionLevel = state.settings.noiseLevel;
|
| 409 |
+
});
|
| 410 |
+
document.getElementById('eqBass').addEventListener('input', (e) => {
|
| 411 |
+
state.settings.bass = parseFloat(e.target.value); updateEqLabel('bassVal', e.target.value);
|
| 412 |
+
if(state.liveNodes.bass) state.liveNodes.bass.gain.value = state.settings.bass;
|
| 413 |
+
});
|
| 414 |
+
document.getElementById('eqTreble').addEventListener('input', (e) => {
|
| 415 |
+
state.settings.treble = parseFloat(e.target.value); updateEqLabel('trebleVal', e.target.value);
|
| 416 |
+
if(state.liveNodes.treble) state.liveNodes.treble.gain.value = state.settings.treble;
|
| 417 |
+
});
|
| 418 |
+
document.getElementById('eqGain').addEventListener('input', (e) => {
|
| 419 |
+
state.settings.gain = parseFloat(e.target.value); updateEqLabel('gainVal', e.target.value);
|
| 420 |
+
if(state.liveNodes.gain) state.liveNodes.gain.gain.value = Math.pow(10, state.settings.gain / 20);
|
| 421 |
+
});
|
| 422 |
+
|
| 423 |
+
// Aesthetic Reset Buttons
|
| 424 |
+
document.getElementById('resetNoise').onclick = () => {
|
| 425 |
+
state.settings.noiseLevel = 100; document.getElementById('noiseLevel').value = 100;
|
| 426 |
+
document.getElementById('noiseLevelValue').textContent = '100%';
|
| 427 |
+
if (state.dfNetProc && state.liveCtx) state.dfNetProc.noiseReductionLevel = 100;
|
| 428 |
+
};
|
| 429 |
+
document.getElementById('resetBass').onclick = () => {
|
| 430 |
+
state.settings.bass = 0; document.getElementById('eqBass').value = 0; updateEqLabel('bassVal', 0);
|
| 431 |
+
if(state.liveNodes.bass) state.liveNodes.bass.gain.value = 0;
|
| 432 |
+
};
|
| 433 |
+
document.getElementById('resetTreble').onclick = () => {
|
| 434 |
+
state.settings.treble = 0; document.getElementById('eqTreble').value = 0; updateEqLabel('trebleVal', 0);
|
| 435 |
+
if(state.liveNodes.treble) state.liveNodes.treble.gain.value = 0;
|
| 436 |
+
};
|
| 437 |
+
document.getElementById('resetGain').onclick = () => {
|
| 438 |
+
state.settings.gain = 0; document.getElementById('eqGain').value = 0; updateEqLabel('gainVal', 0);
|
| 439 |
+
if(state.liveNodes.gain) state.liveNodes.gain.gain.value = 1;
|
| 440 |
+
};
|
| 441 |
+
|
| 442 |
+
const formatWav = document.getElementById('formatWav');
|
| 443 |
+
const formatMp3 = document.getElementById('formatMp3');
|
| 444 |
+
formatWav.onclick = () => { state.settings.format = 'wav'; formatWav.className = 'px-3 py-1.5 text-xs font-bold rounded-md bg-primary-600 text-white transition-all shadow-sm'; formatMp3.className = 'px-3 py-1.5 text-xs font-bold rounded-md text-slate-500 dark:text-slate-400 hover:text-slate-800 dark:hover:text-white transition-all'; };
|
| 445 |
+
formatMp3.onclick = () => { state.settings.format = 'mp3'; formatMp3.className = 'px-3 py-1.5 text-xs font-bold rounded-md bg-primary-600 text-white transition-all shadow-sm'; formatWav.className = 'px-3 py-1.5 text-xs font-bold rounded-md text-slate-500 dark:text-slate-400 hover:text-slate-800 dark:hover:text-white transition-all'; };
|
| 446 |
+
|
| 447 |
+
// --- DRAG & DROP LOGIC ---
|
| 448 |
+
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(e => UI.dropzone.addEventListener(e, ev => { ev.preventDefault(); ev.stopPropagation(); }, false));
|
| 449 |
+
['dragenter', 'dragover'].forEach(e => UI.dropzone.addEventListener(e, () => UI.dropzone.classList.add('drag-active'), false));
|
| 450 |
+
['dragleave', 'drop'].forEach(e => UI.dropzone.addEventListener(e, () => UI.dropzone.classList.remove('drag-active'), false));
|
| 451 |
+
UI.dropzone.addEventListener('drop', (e) => handleFiles(e.dataTransfer.files));
|
| 452 |
+
UI.dropzone.addEventListener('click', () => UI.fileInput.click());
|
| 453 |
+
UI.fileInput.addEventListener('change', (e) => handleFiles(e.target.files));
|
| 454 |
+
|
| 455 |
+
UI.clearAllBtn.onclick = () => {
|
| 456 |
+
state.files = []; state.activeId = null;
|
| 457 |
+
UI.workspaceActive.classList.add('hidden'); UI.workspaceEmpty.classList.remove('hidden');
|
| 458 |
+
if (state.wavesurfer) { state.wavesurfer.destroy(); state.wavesurfer = null; }
|
| 459 |
+
UI.fileInput.value = ''; renderQueue(); teardownLivePipeline();
|
| 460 |
+
};
|
| 461 |
+
|
| 462 |
+
document.addEventListener('keydown', (e) => {
|
| 463 |
+
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') return;
|
| 464 |
+
if (!state.activeId) return;
|
| 465 |
+
switch(e.code) {
|
| 466 |
+
case 'Space': e.preventDefault(); if (state.wavesurfer) state.wavesurfer.playPause(); break;
|
| 467 |
+
case 'ArrowLeft': e.preventDefault(); if (state.wavesurfer) state.wavesurfer.skip(-5); break;
|
| 468 |
+
case 'ArrowRight': e.preventDefault(); if (state.wavesurfer) state.wavesurfer.skip(5); break;
|
| 469 |
+
case 'Delete': case 'Backspace': e.preventDefault(); removeFile(state.activeId); break;
|
| 470 |
+
}
|
| 471 |
+
});
|
| 472 |
+
|
| 473 |
+
// --- FILE HANDLING & QUEUE ---
|
| 474 |
+
function handleFiles(files) {
|
| 475 |
+
let added = false;
|
| 476 |
+
for (let f of files) {
|
| 477 |
+
const ext = f.name.substring(f.name.lastIndexOf('.')).toLowerCase();
|
| 478 |
+
const validExts = ['.mp3', '.wav', '.ogg', '.aac', '.m4a', '.flac', '.wma', '.aiff', '.mp4'];
|
| 479 |
+
if (!f.type.startsWith('audio/') && !f.type.startsWith('video/') && !validExts.includes(ext)) {
|
| 480 |
+
console.warn('Skipped non-audio file:', f.name);
|
| 481 |
+
continue;
|
| 482 |
+
}
|
| 483 |
+
const id = 'f_' + Date.now() + Math.random().toString(36).substr(2, 5);
|
| 484 |
+
state.files.push({
|
| 485 |
+
id, file: f, name: f.name, size: f.size, originalUrl: URL.createObjectURL(f),
|
| 486 |
+
cleanedUrl: null, status: 'pending', duration: 0, startTrim: 0, endTrim: 0
|
| 487 |
+
});
|
| 488 |
+
added = true;
|
| 489 |
+
}
|
| 490 |
+
if (added) {
|
| 491 |
+
renderQueue();
|
| 492 |
+
if (!state.activeId && state.files.length > 0) selectFile(state.files[0].id);
|
| 493 |
+
}
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
function renderQueue() {
|
| 497 |
+
UI.fileList.innerHTML = '';
|
| 498 |
+
UI.queueCount.textContent = `${state.files.length} file${state.files.length !== 1 ? 's' : ''}`;
|
| 499 |
+
|
| 500 |
+
if (state.files.length > 0) {
|
| 501 |
+
UI.dropzoneActions.classList.remove('hidden');
|
| 502 |
+
UI.dropzoneIndicatorText.textContent = `${state.files.length} file(s) ready`;
|
| 503 |
+
UI.dropzone.classList.replace('border-slate-300', 'border-primary-400');
|
| 504 |
+
UI.dropzone.classList.replace('dark:border-slate-600', 'dark:border-primary-500');
|
| 505 |
+
UI.dropzone.classList.add('bg-primary-50/50', 'dark:bg-primary-900/20');
|
| 506 |
+
UI.dropzoneIcon.classList.replace('text-slate-400', 'text-primary-500');
|
| 507 |
+
} else {
|
| 508 |
+
UI.dropzoneActions.classList.add('hidden');
|
| 509 |
+
UI.dropzone.classList.replace('border-primary-400', 'border-slate-300');
|
| 510 |
+
UI.dropzone.classList.replace('dark:border-primary-500', 'dark:border-slate-600');
|
| 511 |
+
UI.dropzone.classList.remove('bg-primary-50/50', 'dark:bg-primary-900/20');
|
| 512 |
+
UI.dropzoneIcon.classList.replace('text-primary-500', 'text-slate-400');
|
| 513 |
+
UI.fileList.innerHTML = '<div class="p-4 text-center text-slate-400 dark:text-slate-500 text-sm italic empty-state">Queue is empty.</div>';
|
| 514 |
+
}
|
| 515 |
+
|
| 516 |
+
state.files.forEach(item => {
|
| 517 |
+
const el = document.createElement('div');
|
| 518 |
+
const isActive = item.id === state.activeId;
|
| 519 |
+
let icon = '<i data-lucide="clock" class="w-4 h-4 text-slate-400"></i>';
|
| 520 |
+
if(item.status === 'processing') icon = '<i data-lucide="loader-2" class="w-4 h-4 text-primary-500 spinner"></i>';
|
| 521 |
+
if(item.status === 'done') icon = '<i data-lucide="check-circle-2" class="w-4 h-4 text-emerald-500 dark:text-emerald-400"></i>';
|
| 522 |
+
|
| 523 |
+
el.className = `p-3 rounded-lg flex items-center justify-between cursor-pointer border transition-all ${isActive ? 'bg-primary-50 dark:bg-primary-900/20 border-primary-500/50' : 'bg-white dark:bg-slate-900 border-slate-200 dark:border-slate-700 hover:border-slate-300 dark:hover:border-slate-500'}`;
|
| 524 |
+
el.innerHTML = `
|
| 525 |
+
<div class="flex items-center gap-3 overflow-hidden">${icon}<span class="text-sm truncate text-slate-700 dark:text-slate-200 ${isActive ? 'font-semibold' : ''}">${item.name}</span></div>
|
| 526 |
+
<button class="p-1 text-slate-400 hover:text-red-500 dark:hover:text-red-400 remove-btn transition-colors" data-id="${item.id}"><i data-lucide="x" class="w-4 h-4"></i></button>
|
| 527 |
+
`;
|
| 528 |
+
el.onclick = (e) => { if(!e.target.closest('.remove-btn')) selectFile(item.id); };
|
| 529 |
+
el.querySelector('.remove-btn').onclick = () => removeFile(item.id);
|
| 530 |
+
UI.fileList.appendChild(el);
|
| 531 |
+
});
|
| 532 |
+
|
| 533 |
+
updateProcessButtonText();
|
| 534 |
+
const doneCount = state.files.filter(f => f.status === 'done').length;
|
| 535 |
+
UI.downloadZipBtn.classList.toggle('hidden', doneCount < 1);
|
| 536 |
+
}
|
| 537 |
+
|
| 538 |
+
function removeFile(id) {
|
| 539 |
+
state.files = state.files.filter(f => f.id !== id);
|
| 540 |
+
if (state.activeId === id) {
|
| 541 |
+
state.activeId = null;
|
| 542 |
+
UI.workspaceActive.classList.add('hidden');
|
| 543 |
+
UI.workspaceEmpty.classList.remove('hidden');
|
| 544 |
+
if (state.wavesurfer) state.wavesurfer.destroy();
|
| 545 |
+
state.wavesurfer = null;
|
| 546 |
+
teardownLivePipeline();
|
| 547 |
+
}
|
| 548 |
+
renderQueue();
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
// --- WORKSPACE, LIVE PREVIEW & WAVESURFER ---
|
| 552 |
+
async function selectFile(id) {
|
| 553 |
+
state.activeId = id; renderQueue();
|
| 554 |
+
const item = state.files.find(f => f.id === id);
|
| 555 |
+
|
| 556 |
+
UI.workspaceEmpty.classList.add('hidden');
|
| 557 |
+
UI.workspaceActive.classList.remove('hidden');
|
| 558 |
+
UI.activeFileName.textContent = item.name;
|
| 559 |
+
|
| 560 |
+
// Manage Processed button state
|
| 561 |
+
if (item.status === 'done') {
|
| 562 |
+
UI.btnPreview.classList.add('hidden');
|
| 563 |
+
|
| 564 |
+
UI.btnCleaned.classList.remove('opacity-50', 'cursor-not-allowed', 'text-slate-400', 'dark:text-slate-600');
|
| 565 |
+
UI.btnCleaned.classList.add('text-slate-500', 'dark:text-slate-400', 'hover:text-slate-800', 'dark:hover:text-white');
|
| 566 |
+
UI.btnCleaned.disabled = false;
|
| 567 |
+
UI.btnCleaned.title = "Play the final baked output";
|
| 568 |
+
|
| 569 |
+
UI.downloadSingleBtn.classList.remove('hidden');
|
| 570 |
+
setPlaybackMode('cleaned', item);
|
| 571 |
+
} else {
|
| 572 |
+
UI.btnPreview.classList.remove('hidden');
|
| 573 |
+
|
| 574 |
+
UI.btnCleaned.classList.remove('text-slate-500', 'dark:text-slate-400', 'hover:text-slate-800', 'dark:hover:text-white');
|
| 575 |
+
UI.btnCleaned.classList.add('opacity-50', 'cursor-not-allowed', 'text-slate-400', 'dark:text-slate-600');
|
| 576 |
+
UI.btnCleaned.disabled = true;
|
| 577 |
+
UI.btnCleaned.title = "Must Process first to unlock the final baked file";
|
| 578 |
+
|
| 579 |
+
UI.downloadSingleBtn.classList.add('hidden');
|
| 580 |
+
setPlaybackMode('original', item);
|
| 581 |
+
}
|
| 582 |
+
|
| 583 |
+
initWavesurfer(item);
|
| 584 |
+
}
|
| 585 |
+
|
| 586 |
+
function initWavesurfer(item) {
|
| 587 |
+
if (state.wavesurfer) state.wavesurfer.destroy();
|
| 588 |
+
|
| 589 |
+
setProcessButtonState(true, "Loading Audio...");
|
| 590 |
+
|
| 591 |
+
// Memory Protection: Spectrogram crashes tabs on massive audio files. Disable if > 15MB.
|
| 592 |
+
const isMassive = item.size > 15 * 1024 * 1024;
|
| 593 |
+
const plugins = [];
|
| 594 |
+
const specContainer = document.getElementById('spectrogram');
|
| 595 |
+
|
| 596 |
+
if (!isMassive) {
|
| 597 |
+
specContainer.innerHTML = '';
|
| 598 |
+
plugins.push(
|
| 599 |
+
Spectrogram.create({
|
| 600 |
+
container: '#spectrogram',
|
| 601 |
+
labels: true,
|
| 602 |
+
height: 80,
|
| 603 |
+
splitChannels: false
|
| 604 |
+
})
|
| 605 |
+
);
|
| 606 |
+
} else {
|
| 607 |
+
specContainer.innerHTML = '<div class="flex items-center justify-center h-20 text-xs text-slate-500 bg-slate-900/10 dark:bg-slate-900/40 border border-dashed border-slate-300 dark:border-slate-700 rounded-lg mx-2 mb-2">Spectrogram disabled for massive files to prevent browser memory crash.</div>';
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
state.wavesurfer = WaveSurfer.create({
|
| 611 |
+
container: '#waveform', waveColor: '#94a3b8', progressColor: '#8b5cf6',
|
| 612 |
+
cursorColor: '#a78bfa', barWidth: 2, barGap: 1, barRadius: 2, height: 100, normalize: true,
|
| 613 |
+
plugins: plugins
|
| 614 |
+
});
|
| 615 |
+
|
| 616 |
+
const loadUrl = state.playbackMode === 'cleaned' ? item.cleanedUrl : item.originalUrl;
|
| 617 |
+
state.wavesurfer.load(loadUrl);
|
| 618 |
+
|
| 619 |
+
UI.zoomSlider.value = 0;
|
| 620 |
+
|
| 621 |
+
state.wavesurfer.on('ready', () => {
|
| 622 |
+
setProcessButtonState(false);
|
| 623 |
+
const duration = state.wavesurfer.getDuration();
|
| 624 |
+
if (item.duration === 0) { item.duration = duration; item.endTrim = duration; }
|
| 625 |
+
|
| 626 |
+
UI.trimStart.max = duration; UI.trimEnd.max = duration;
|
| 627 |
+
UI.trimStart.value = item.startTrim.toFixed(1); UI.trimEnd.value = item.endTrim.toFixed(1);
|
| 628 |
+
|
| 629 |
+
updateTimeDisplay();
|
| 630 |
+
UI.iconPlayWrap.classList.replace('hidden', 'flex');
|
| 631 |
+
UI.iconPauseWrap.classList.replace('flex', 'hidden');
|
| 632 |
+
});
|
| 633 |
+
|
| 634 |
+
state.wavesurfer.on('audioprocess', updateTimeDisplay);
|
| 635 |
+
state.wavesurfer.on('seek', updateTimeDisplay);
|
| 636 |
+
state.wavesurfer.on('play', () => { UI.iconPlayWrap.classList.replace('flex', 'hidden'); UI.iconPauseWrap.classList.replace('hidden', 'flex'); });
|
| 637 |
+
state.wavesurfer.on('pause', () => { UI.iconPauseWrap.classList.replace('flex', 'hidden'); UI.iconPlayWrap.classList.replace('hidden', 'flex'); });
|
| 638 |
+
}
|
| 639 |
+
|
| 640 |
+
UI.zoomSlider.addEventListener('input', (e) => {
|
| 641 |
+
if (state.wavesurfer) state.wavesurfer.zoom(Number(e.target.value));
|
| 642 |
+
});
|
| 643 |
+
|
| 644 |
+
function updateTimeDisplay() {
|
| 645 |
+
if(!state.wavesurfer) return;
|
| 646 |
+
const cur = state.wavesurfer.getCurrentTime(), tot = state.wavesurfer.getDuration() || 0;
|
| 647 |
+
UI.timeDisplay.textContent = `${formatTime(cur)} / ${formatTime(tot)}`;
|
| 648 |
+
|
| 649 |
+
const item = state.files.find(f => f.id === state.activeId);
|
| 650 |
+
if(item && item.status === 'pending') {
|
| 651 |
+
if (cur > item.endTrim && state.wavesurfer.isPlaying()) {
|
| 652 |
+
state.wavesurfer.pause(); state.wavesurfer.setTime(item.startTrim);
|
| 653 |
+
}
|
| 654 |
+
}
|
| 655 |
+
}
|
| 656 |
+
function formatTime(sec) { const m = Math.floor(sec / 60), s = Math.floor(sec % 60); return `${m.toString().padStart(2, '0')}:${s.toString().padStart(2, '0')}`; }
|
| 657 |
+
|
| 658 |
+
UI.playBtn.onclick = () => state.wavesurfer && state.wavesurfer.playPause();
|
| 659 |
+
|
| 660 |
+
document.getElementById('setStartBtn').onclick = () => { if(state.wavesurfer){ UI.trimStart.value = state.wavesurfer.getCurrentTime().toFixed(1); saveTrim(); }};
|
| 661 |
+
document.getElementById('setEndBtn').onclick = () => { if(state.wavesurfer){ UI.trimEnd.value = state.wavesurfer.getCurrentTime().toFixed(1); saveTrim(); }};
|
| 662 |
+
UI.trimStart.onchange = saveTrim; UI.trimEnd.onchange = saveTrim;
|
| 663 |
+
|
| 664 |
+
function saveTrim() {
|
| 665 |
+
const item = state.files.find(f => f.id === state.activeId);
|
| 666 |
+
if(!item || item.status !== 'pending') return;
|
| 667 |
+
let start = parseFloat(UI.trimStart.value) || 0, end = parseFloat(UI.trimEnd.value) || item.duration;
|
| 668 |
+
if(start < 0) start = 0; if(end > item.duration) end = item.duration; if(start >= end) start = end - 0.1;
|
| 669 |
+
UI.trimStart.value = start.toFixed(1); UI.trimEnd.value = end.toFixed(1);
|
| 670 |
+
item.startTrim = start; item.endTrim = end;
|
| 671 |
+
}
|
| 672 |
+
|
| 673 |
+
// Live Preview Routing Logic
|
| 674 |
+
async function setupLivePipeline() {
|
| 675 |
+
if (!state.liveCtx) {
|
| 676 |
+
// MIGRATION: 16kHz context for Hush
|
| 677 |
+
state.liveCtx = new (window.AudioContext || window.webkitAudioContext)({ sampleRate: 16000 });
|
| 678 |
+
state.liveNodes = {};
|
| 679 |
+
}
|
| 680 |
+
if (state.liveCtx.state === 'suspended') await state.liveCtx.resume();
|
| 681 |
+
|
| 682 |
+
const mediaElt = state.wavesurfer.getMediaElement();
|
| 683 |
+
if (!mediaElt.audioNodeMap) {
|
| 684 |
+
state.mediaNode = state.liveCtx.createMediaElementSource(mediaElt);
|
| 685 |
+
mediaElt.audioNodeMap = state.mediaNode;
|
| 686 |
+
} else {
|
| 687 |
+
state.mediaNode = mediaElt.audioNodeMap;
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
state.mediaNode.disconnect();
|
| 691 |
+
if(state.liveNodes.dfNode) state.liveNodes.dfNode.disconnect();
|
| 692 |
+
if(state.liveNodes.bass) state.liveNodes.bass.disconnect();
|
| 693 |
+
if(state.liveNodes.treble) state.liveNodes.treble.disconnect();
|
| 694 |
+
if(state.liveNodes.gain) state.liveNodes.gain.disconnect();
|
| 695 |
+
|
| 696 |
+
state.liveNodes.dfNode = await state.dfNetProc.createAudioWorkletNode(state.liveCtx);
|
| 697 |
+
|
| 698 |
+
state.liveNodes.bass = state.liveCtx.createBiquadFilter(); state.liveNodes.bass.type = 'lowshelf'; state.liveNodes.bass.frequency.value = 250; state.liveNodes.bass.gain.value = state.settings.bass;
|
| 699 |
+
state.liveNodes.treble = state.liveCtx.createBiquadFilter(); state.liveNodes.treble.type = 'highshelf'; state.liveNodes.treble.frequency.value = 4000; state.liveNodes.treble.gain.value = state.settings.treble;
|
| 700 |
+
state.liveNodes.gain = state.liveCtx.createGain(); state.liveNodes.gain.gain.value = Math.pow(10, state.settings.gain / 20);
|
| 701 |
+
|
| 702 |
+
state.mediaNode.connect(state.liveNodes.dfNode);
|
| 703 |
+
state.liveNodes.dfNode.connect(state.liveNodes.bass);
|
| 704 |
+
state.liveNodes.bass.connect(state.liveNodes.treble);
|
| 705 |
+
state.liveNodes.treble.connect(state.liveNodes.gain);
|
| 706 |
+
state.liveNodes.gain.connect(state.liveCtx.destination);
|
| 707 |
+
}
|
| 708 |
+
|
| 709 |
+
function teardownLivePipeline() {
|
| 710 |
+
if (state.mediaNode && state.liveCtx) {
|
| 711 |
+
state.mediaNode.disconnect();
|
| 712 |
+
state.mediaNode.connect(state.liveCtx.destination);
|
| 713 |
+
}
|
| 714 |
+
}
|
| 715 |
+
|
| 716 |
+
// A/B/Live Toggle Logic
|
| 717 |
+
UI.btnOriginal.onclick = () => setPlaybackMode('original', state.files.find(f=>f.id===state.activeId));
|
| 718 |
+
UI.btnPreview.onclick = () => setPlaybackMode('preview', state.files.find(f=>f.id===state.activeId));
|
| 719 |
+
UI.btnCleaned.onclick = () => { if(!UI.btnCleaned.disabled) setPlaybackMode('cleaned', state.files.find(f=>f.id===state.activeId)); };
|
| 720 |
+
|
| 721 |
+
async function setPlaybackMode(mode, item) {
|
| 722 |
+
if (!item || !state.wavesurfer) return;
|
| 723 |
+
state.playbackMode = mode;
|
| 724 |
+
|
| 725 |
+
const baseClass = 'px-4 py-1.5 text-xs font-bold rounded-md transition-all shadow-sm ';
|
| 726 |
+
const activeClass = 'bg-white dark:bg-slate-700 text-slate-800 dark:text-white';
|
| 727 |
+
const inactiveClass = 'text-slate-500 dark:text-slate-400 hover:text-slate-800 dark:hover:text-white';
|
| 728 |
+
|
| 729 |
+
UI.btnOriginal.className = baseClass + (mode === 'original' ? activeClass : inactiveClass);
|
| 730 |
+
UI.btnPreview.className = baseClass + (mode === 'preview' ? 'bg-fuchsia-600 text-white' : inactiveClass);
|
| 731 |
+
|
| 732 |
+
if (item.status === 'done') {
|
| 733 |
+
UI.btnCleaned.className = baseClass + (mode === 'cleaned' ? 'bg-primary-600 text-white' : inactiveClass);
|
| 734 |
+
}
|
| 735 |
+
|
| 736 |
+
if (mode === 'original') state.wavesurfer.setOptions({ waveColor: '#94a3b8', progressColor: '#cbd5e1' });
|
| 737 |
+
else if (mode === 'preview') state.wavesurfer.setOptions({ waveColor: '#d946ef', progressColor: '#fdf4ff' });
|
| 738 |
+
else if (mode === 'cleaned') state.wavesurfer.setOptions({ waveColor: '#4c1d95', progressColor: '#8b5cf6' });
|
| 739 |
+
|
| 740 |
+
const curTime = state.wavesurfer.getCurrentTime();
|
| 741 |
+
const wasPlaying = state.wavesurfer.isPlaying();
|
| 742 |
+
if (wasPlaying) state.wavesurfer.pause();
|
| 743 |
+
|
| 744 |
+
try {
|
| 745 |
+
if (mode === 'preview') {
|
| 746 |
+
await setupLivePipeline();
|
| 747 |
+
if(state.wavesurfer.getMediaElement().src !== item.originalUrl) await state.wavesurfer.load(item.originalUrl);
|
| 748 |
+
} else {
|
| 749 |
+
teardownLivePipeline();
|
| 750 |
+
const targetUrl = mode === 'cleaned' ? item.cleanedUrl : item.originalUrl;
|
| 751 |
+
if(state.wavesurfer.getMediaElement().src !== targetUrl) await state.wavesurfer.load(targetUrl);
|
| 752 |
+
}
|
| 753 |
+
state.wavesurfer.setTime(curTime);
|
| 754 |
+
if(wasPlaying) state.wavesurfer.play();
|
| 755 |
+
} catch(e) {
|
| 756 |
+
console.error(e);
|
| 757 |
+
alert("Could not switch playback mode.");
|
| 758 |
+
}
|
| 759 |
+
}
|
| 760 |
+
|
| 761 |
+
// --- OFFLINE PROCESSING ENGINE ---
|
| 762 |
+
UI.processBtn.onclick = async () => {
|
| 763 |
+
const pending = state.files.filter(f => f.status === 'pending');
|
| 764 |
+
if (pending.length === 0) return;
|
| 765 |
+
|
| 766 |
+
setProcessButtonState(true, "Preparing Hush AI...");
|
| 767 |
+
|
| 768 |
+
try {
|
| 769 |
+
// MIGRATION: 16kHz for Hush Offline Nodes
|
| 770 |
+
const offlineProcL = new state.ProcessorClass({ sampleRate: 16000, noiseReductionLevel: state.settings.noiseLevel, assetConfig: state.assetConfigObj });
|
| 771 |
+
const offlineProcR = new state.ProcessorClass({ sampleRate: 16000, noiseReductionLevel: state.settings.noiseLevel, assetConfig: state.assetConfigObj });
|
| 772 |
+
|
| 773 |
+
await Promise.all([offlineProcL.initialize(), offlineProcR.initialize()]);
|
| 774 |
+
// MIGRATION: 16kHz context forces browser to downsample audio natively!
|
| 775 |
+
const audioCtx = new (window.AudioContext || window.webkitAudioContext)({ sampleRate: 16000 });
|
| 776 |
+
|
| 777 |
+
for (let i = 0; i < pending.length; i++) {
|
| 778 |
+
const item = pending[i]; item.status = 'processing'; renderQueue();
|
| 779 |
+
const tag = `(${i+1}/${pending.length})`;
|
| 780 |
+
|
| 781 |
+
setProcessButtonState(true, `Decoding Audio ${tag}...`);
|
| 782 |
+
await new Promise(r => setTimeout(r, 10)); // Force paint
|
| 783 |
+
|
| 784 |
+
const arrayBuffer = await item.file.arrayBuffer();
|
| 785 |
+
let decodedBuffer = await audioCtx.decodeAudioData(arrayBuffer);
|
| 786 |
+
|
| 787 |
+
if (item.endTrim > 0 && (item.startTrim > 0 || item.endTrim < decodedBuffer.duration)) {
|
| 788 |
+
const startSample = Math.floor(item.startTrim * 16000); // 16kHz sample rate
|
| 789 |
+
let endSample = Math.floor(item.endTrim * 16000);
|
| 790 |
+
if (endSample > decodedBuffer.length) endSample = decodedBuffer.length;
|
| 791 |
+
const len = endSample - startSample;
|
| 792 |
+
const trimmed = new AudioContext({sampleRate: 16000}).createBuffer(decodedBuffer.numberOfChannels, len, 16000);
|
| 793 |
+
for(let c=0; c<decodedBuffer.numberOfChannels; c++) trimmed.copyToChannel(decodedBuffer.getChannelData(c).subarray(startSample, endSample), c);
|
| 794 |
+
decodedBuffer = trimmed;
|
| 795 |
+
}
|
| 796 |
+
|
| 797 |
+
// --- STEREO PRESERVATION LOGIC ---
|
| 798 |
+
const isStereoFile = decodedBuffer.numberOfChannels > 1;
|
| 799 |
+
const processStereo = state.settings.stereo && isStereoFile;
|
| 800 |
+
const channels = processStereo ? 2 : 1;
|
| 801 |
+
|
| 802 |
+
const offlineCtx = new OfflineAudioContext(channels, decodedBuffer.length, 16000);
|
| 803 |
+
const sourceNode = offlineCtx.createBufferSource();
|
| 804 |
+
let pipelineTail = null;
|
| 805 |
+
|
| 806 |
+
if (processStereo) {
|
| 807 |
+
sourceNode.buffer = decodedBuffer;
|
| 808 |
+
const splitter = offlineCtx.createChannelSplitter(2);
|
| 809 |
+
const merger = offlineCtx.createChannelMerger(2);
|
| 810 |
+
sourceNode.connect(splitter);
|
| 811 |
+
|
| 812 |
+
const dfNodeL = await offlineProcL.createAudioWorkletNode(offlineCtx);
|
| 813 |
+
const dfNodeR = await offlineProcR.createAudioWorkletNode(offlineCtx);
|
| 814 |
+
|
| 815 |
+
splitter.connect(dfNodeL, 0, 0);
|
| 816 |
+
splitter.connect(dfNodeR, 1, 0);
|
| 817 |
+
dfNodeL.connect(merger, 0, 0);
|
| 818 |
+
dfNodeR.connect(merger, 0, 1);
|
| 819 |
+
|
| 820 |
+
pipelineTail = merger;
|
| 821 |
+
} else {
|
| 822 |
+
if (isStereoFile) {
|
| 823 |
+
const mono = offlineCtx.createBuffer(1, decodedBuffer.length, 16000);
|
| 824 |
+
const data = mono.getChannelData(0), left = decodedBuffer.getChannelData(0), right = decodedBuffer.getChannelData(1);
|
| 825 |
+
for (let j = 0; j < decodedBuffer.length; j++) data[j] = (left[j] + right[j]) / 2;
|
| 826 |
+
decodedBuffer = mono; // Memory Optimization! Drops the heavy stereo buffer
|
| 827 |
+
}
|
| 828 |
+
sourceNode.buffer = decodedBuffer;
|
| 829 |
+
const dfNode = await offlineProcL.createAudioWorkletNode(offlineCtx);
|
| 830 |
+
sourceNode.connect(dfNode);
|
| 831 |
+
pipelineTail = dfNode;
|
| 832 |
+
}
|
| 833 |
+
|
| 834 |
+
// Apply Post-Processing EQ
|
| 835 |
+
const bassEq = offlineCtx.createBiquadFilter(); bassEq.type = 'lowshelf'; bassEq.frequency.value = 250; bassEq.gain.value = state.settings.bass;
|
| 836 |
+
const trebleEq = offlineCtx.createBiquadFilter(); trebleEq.type = 'highshelf'; trebleEq.frequency.value = 4000; trebleEq.gain.value = state.settings.treble;
|
| 837 |
+
const gainNode = offlineCtx.createGain(); gainNode.gain.value = Math.pow(10, state.settings.gain / 20);
|
| 838 |
+
|
| 839 |
+
pipelineTail.connect(bassEq);
|
| 840 |
+
bassEq.connect(trebleEq);
|
| 841 |
+
trebleEq.connect(gainNode);
|
| 842 |
+
gainNode.connect(offlineCtx.destination);
|
| 843 |
+
|
| 844 |
+
offlineCtx.suspend(0.1).then(() => { setTimeout(() => offlineCtx.resume(), 100); });
|
| 845 |
+
|
| 846 |
+
// Memory Protection: Track progress of massive AI rendering
|
| 847 |
+
const dur = decodedBuffer.duration;
|
| 848 |
+
const interval = Math.max(5, dur / 100);
|
| 849 |
+
for (let t = Math.ceil(interval); t < dur; t += interval) {
|
| 850 |
+
offlineCtx.suspend(t).then(async () => {
|
| 851 |
+
const pct = Math.round((t / dur) * 100);
|
| 852 |
+
setProcessButtonState(true, `Cleaning ${tag} - ${pct}%`);
|
| 853 |
+
await new Promise(r => setTimeout(r, 0));
|
| 854 |
+
offlineCtx.resume();
|
| 855 |
+
});
|
| 856 |
+
}
|
| 857 |
+
|
| 858 |
+
sourceNode.start(0);
|
| 859 |
+
const renderedBuffer = await offlineCtx.startRendering();
|
| 860 |
+
|
| 861 |
+
if (state.settings.normalize) {
|
| 862 |
+
for(let c=0; c<renderedBuffer.numberOfChannels; c++) {
|
| 863 |
+
const dat = renderedBuffer.getChannelData(c);
|
| 864 |
+
let max = 0;
|
| 865 |
+
for(let j=0; j<dat.length; j++) { if(Math.abs(dat[j]) > max) max = Math.abs(dat[j]); }
|
| 866 |
+
if (max > 0) { const multiplier = 0.95 / max; for(let j=0; j<dat.length; j++) dat[j] *= multiplier; }
|
| 867 |
+
}
|
| 868 |
+
}
|
| 869 |
+
|
| 870 |
+
let outBlob;
|
| 871 |
+
if (state.settings.format === 'mp3') {
|
| 872 |
+
outBlob = await encodeToMP3(renderedBuffer, (p) => {
|
| 873 |
+
setProcessButtonState(true, `Encoding MP3 ${tag} - ${Math.round(p * 100)}%`);
|
| 874 |
+
});
|
| 875 |
+
} else {
|
| 876 |
+
outBlob = await audioBufferToWav(renderedBuffer, (p) => {
|
| 877 |
+
setProcessButtonState(true, `Saving WAV ${tag} - ${Math.round(p * 100)}%`);
|
| 878 |
+
});
|
| 879 |
+
}
|
| 880 |
+
|
| 881 |
+
item.cleanedUrl = URL.createObjectURL(outBlob); item.blob = outBlob; item.status = 'done';
|
| 882 |
+
decodedBuffer = null;
|
| 883 |
+
}
|
| 884 |
+
|
| 885 |
+
setProcessButtonState(false); renderQueue();
|
| 886 |
+
if(state.activeId) selectFile(state.activeId);
|
| 887 |
+
|
| 888 |
+
} catch (err) {
|
| 889 |
+
console.error(err); alert("An error occurred during processing. The file may be too large for browser memory limits."); setProcessButtonState(false);
|
| 890 |
+
}
|
| 891 |
+
};
|
| 892 |
+
|
| 893 |
+
// --- HIGH-PERFORMANCE ASYNC ENCODERS ---
|
| 894 |
+
async function audioBufferToWav(buffer, onProgress) {
|
| 895 |
+
const numOfChan = buffer.numberOfChannels, len = buffer.length * numOfChan * 2 + 44;
|
| 896 |
+
const view = new DataView(new ArrayBuffer(len)), channels = [];
|
| 897 |
+
let offset = 0, pos = 0;
|
| 898 |
+
const setU16 = d => { view.setUint16(offset, d, true); offset += 2; };
|
| 899 |
+
const setU32 = d => { view.setUint32(offset, d, true); offset += 4; };
|
| 900 |
+
|
| 901 |
+
setU32(0x46464952); setU32(len - 8); setU32(0x45564157); setU32(0x20746d66); setU32(16); setU16(1); setU16(numOfChan);
|
| 902 |
+
setU32(buffer.sampleRate); setU32(buffer.sampleRate * 2 * numOfChan); setU16(numOfChan * 2); setU16(16); setU32(0x61746164); setU32(len - pos - 4);
|
| 903 |
+
|
| 904 |
+
for(let i=0; i<numOfChan; i++) channels.push(buffer.getChannelData(i));
|
| 905 |
+
|
| 906 |
+
const chunk = buffer.sampleRate * 5;
|
| 907 |
+
while(pos < buffer.length) {
|
| 908 |
+
let end = Math.min(pos + chunk, buffer.length);
|
| 909 |
+
while(pos < end) {
|
| 910 |
+
for(let i=0; i<numOfChan; i++) {
|
| 911 |
+
let s = Math.max(-1, Math.min(1, channels[i][pos]));
|
| 912 |
+
setU16(s < 0 ? s * 0x8000 : s * 0x7FFF);
|
| 913 |
+
}
|
| 914 |
+
pos++;
|
| 915 |
+
}
|
| 916 |
+
if(onProgress) onProgress(pos / buffer.length);
|
| 917 |
+
await new Promise(r => setTimeout(r, 0)); // Prevents UI freeze
|
| 918 |
+
}
|
| 919 |
+
return new Blob([view.buffer], { type: "audio/wav" });
|
| 920 |
+
}
|
| 921 |
+
|
| 922 |
+
async function encodeToMP3(audioBuffer, onProgress) {
|
| 923 |
+
const encoder = new lamejs.Mp3Encoder(1, audioBuffer.sampleRate, 192);
|
| 924 |
+
const samples = audioBuffer.getChannelData(0);
|
| 925 |
+
const mp3Data = [];
|
| 926 |
+
const blockSize = 11520; // Massive Memory Fix: Process strictly in small 10-frame sliding windows
|
| 927 |
+
const chunkBuffer = new Int16Array(blockSize);
|
| 928 |
+
|
| 929 |
+
for (let i = 0; i < samples.length; i += blockSize) {
|
| 930 |
+
const end = Math.min(i + blockSize, samples.length);
|
| 931 |
+
const view = chunkBuffer.subarray(0, end - i);
|
| 932 |
+
|
| 933 |
+
for (let j = 0; j < view.length; j++) {
|
| 934 |
+
let s = samples[i + j];
|
| 935 |
+
s = Math.max(-1, Math.min(1, s));
|
| 936 |
+
view[j] = s < 0 ? s * 0x8000 : s * 0x7FFF;
|
| 937 |
+
}
|
| 938 |
+
|
| 939 |
+
const buf = encoder.encodeBuffer(view);
|
| 940 |
+
if (buf.length > 0) mp3Data.push(buf);
|
| 941 |
+
|
| 942 |
+
// Yield control to browser UI every ~3 seconds of audio
|
| 943 |
+
if (i % (audioBuffer.sampleRate * 3) < blockSize) {
|
| 944 |
+
if(onProgress) onProgress(i / samples.length);
|
| 945 |
+
await new Promise(r => setTimeout(r, 0));
|
| 946 |
+
}
|
| 947 |
+
}
|
| 948 |
+
|
| 949 |
+
const flush = encoder.flush(); if (flush.length > 0) mp3Data.push(flush);
|
| 950 |
+
return new Blob(mp3Data, { type: 'audio/mp3' });
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
// --- DOWNLOAD ACTIONS ---
|
| 954 |
+
UI.downloadSingleBtn.onclick = () => {
|
| 955 |
+
const item = state.files.find(f => f.id === state.activeId);
|
| 956 |
+
if(!item || !item.cleanedUrl) return;
|
| 957 |
+
const ext = state.settings.format === 'mp3' ? '.mp3' : '.wav';
|
| 958 |
+
const a = document.createElement('a'); a.href = item.cleanedUrl; a.download = `Hush_Cleaned_${item.name.replace(/\.[^/.]+$/, "")}${ext}`; a.click();
|
| 959 |
+
};
|
| 960 |
+
|
| 961 |
+
UI.downloadZipBtn.onclick = async () => {
|
| 962 |
+
const doneFiles = state.files.filter(f => f.status === 'done');
|
| 963 |
+
if(doneFiles.length === 0) return;
|
| 964 |
+
|
| 965 |
+
const oldHtml = UI.downloadZipBtn.innerHTML;
|
| 966 |
+
UI.downloadZipBtn.disabled = true;
|
| 967 |
+
UI.downloadZipBtn.innerHTML = `<i data-lucide="loader-2" class="w-4 h-4 spinner"></i> Zipping...`;
|
| 968 |
+
lucide.createIcons();
|
| 969 |
+
await new Promise(r => setTimeout(r, 10)); // Force UI Paint
|
| 970 |
+
|
| 971 |
+
const zip = new JSZip(); const ext = state.settings.format === 'mp3' ? '.mp3' : '.wav';
|
| 972 |
+
doneFiles.forEach(f => { zip.file(`Hush_Cleaned_${f.name.replace(/\.[^/.]+$/, "")}${ext}`, f.blob); });
|
| 973 |
+
const content = await zip.generateAsync({type:"blob"});
|
| 974 |
+
|
| 975 |
+
UI.downloadZipBtn.disabled = false;
|
| 976 |
+
UI.downloadZipBtn.innerHTML = oldHtml;
|
| 977 |
+
lucide.createIcons();
|
| 978 |
+
|
| 979 |
+
const a = document.createElement('a'); a.href = URL.createObjectURL(content); a.download = "HushAI_Batch.zip"; a.click();
|
| 980 |
+
};
|
| 981 |
+
</script>
|
| 982 |
+
</body>
|
| 983 |
+
</html>
|