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