denoiser-api / app_connected.html
Clearwave48's picture
Create app_connected.html
8c3bee7 verified
Raw History Blame Contribute Delete
27.3 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>CleanVoice β€” Denoiser</title>
<link href="https://fonts.googleapis.com/css2?family=Syne:wght@400;600;800&family=JetBrains+Mono:wght@300;400;500&display=swap" rel="stylesheet"/>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #0a0a0f;
--surface: #11111a;
--surface2: #1a1a28;
--border: #2a2a3f;
--accent: #7c6aff;
--accent2: #ff6a9b;
--text: #e8e8f0;
--muted: #6b6b88;
--success: #4dffb4;
--danger: #ff4d6a;
--warning: #ffb347;
--radius: 16px;
}
body {
background: var(--bg); color: var(--text);
font-family: 'Syne', sans-serif;
min-height: 100vh; display: flex; flex-direction: column;
align-items: center; justify-content: flex-start;
padding: 48px 20px 80px; overflow-x: hidden;
}
body::before {
content: ''; position: fixed; inset: 0;
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
pointer-events: none; z-index: 0; opacity: .4;
}
.orb { position: fixed; border-radius: 50%; filter: blur(120px); pointer-events: none; z-index: 0; }
.orb-1 { width: 500px; height: 500px; background: rgba(124,106,255,.12); top: -150px; left: -100px; }
.orb-2 { width: 400px; height: 400px; background: rgba(255,106,155,.1); bottom: -100px; right: -80px; }
.wrapper { position: relative; z-index: 1; width: 100%; max-width: 640px; }
header { text-align: center; margin-bottom: 48px; }
.logo-badge {
display: inline-flex; align-items: center; gap: 8px;
background: var(--surface2); border: 1px solid var(--border);
padding: 6px 14px; border-radius: 999px;
font-family: 'JetBrains Mono', monospace; font-size: 11px;
color: var(--accent); letter-spacing: .12em; text-transform: uppercase; margin-bottom: 20px;
}
.logo-badge span { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; animation: pulse 2s infinite; }
h1 { font-size: clamp(2rem,6vw,3.2rem); font-weight: 800; line-height: 1.1;
background: linear-gradient(135deg,#fff 30%,var(--accent));
-webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.subtitle { color: var(--muted); font-size: .95rem; margin-top: 10px; letter-spacing: .02em; }
.card {
background: var(--surface); border: 1px solid var(--border);
border-radius: var(--radius); padding: 32px;
box-shadow: 0 0 0 1px rgba(255,255,255,.03), 0 24px 64px rgba(0,0,0,.5);
margin-bottom: 24px; animation: fadeUp .5s ease both;
}
.card-label {
font-family: 'JetBrains Mono', monospace; font-size: 10px;
letter-spacing: .15em; text-transform: uppercase; color: var(--muted);
margin-bottom: 20px; display: flex; align-items: center; gap: 8px;
}
.card-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.tabs {
display: grid; grid-template-columns: 1fr 1fr;
background: var(--bg); border: 1px solid var(--border);
border-radius: 10px; padding: 4px; margin-bottom: 28px; gap: 4px;
}
.tab-btn {
padding: 10px; border: none; border-radius: 7px;
background: transparent; color: var(--muted);
font-family: 'Syne', sans-serif; font-size: .875rem; font-weight: 600;
cursor: pointer; transition: all .2s; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.tab-btn.active { background: var(--surface2); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.4); }
.tab-btn:hover:not(.active) { color: var(--text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn .2s ease; }
.upload-zone {
border: 2px dashed var(--border); border-radius: 12px;
padding: 40px 24px; text-align: center; cursor: pointer; transition: all .25s;
}
.upload-zone:hover, .upload-zone.drag-over { border-color: var(--accent); background: rgba(124,106,255,.05); }
.upload-zone input[type=file] { display: none; }
.upload-icon { font-size: 2.5rem; margin-bottom: 12px; display: block; }
.upload-zone p { color: var(--muted); font-size: .875rem; }
.upload-zone strong { color: var(--text); }
.upload-zone .formats { font-family: 'JetBrains Mono', monospace; font-size: .75rem; color: var(--muted); margin-top: 8px; opacity: .7; }
.file-preview { display: none; align-items: center; gap: 12px; background: var(--surface2); border-radius: 10px; padding: 14px 16px; margin-top: 16px; }
.file-preview.visible { display: flex; }
.file-icon { font-size: 1.4rem; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: .875rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-family: 'JetBrains Mono', monospace; font-size: .75rem; color: var(--muted); }
.file-remove { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 4px; transition: color .2s; }
.file-remove:hover { color: var(--danger); }
.recorder-area { display: flex; flex-direction: column; align-items: center; gap: 24px; }
.record-btn {
width: 96px; height: 96px; border-radius: 50%; border: 2px solid var(--border);
background: var(--surface2); cursor: pointer; display: flex; align-items: center;
justify-content: center; font-size: 2rem; transition: all .2s; position: relative;
}
.record-btn:hover { border-color: var(--accent); transform: scale(1.04); }
.record-btn.recording { border-color: var(--danger); background: rgba(255,77,106,.1); animation: recPulse 1.4s ease-in-out infinite; }
.record-btn .rec-dot { width: 28px; height: 28px; border-radius: 50%; background: var(--danger); transition: all .3s; }
.record-btn.recording .rec-dot { border-radius: 6px; transform: scale(.8); }
.rec-timer { font-family: 'JetBrains Mono', monospace; font-size: 2rem; font-weight: 300; color: var(--text); letter-spacing: .08em; min-width: 100px; text-align: center; }
.rec-status { font-size: .8rem; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; font-family: 'JetBrains Mono', monospace; }
.rec-status.live { color: var(--danger); }
.waveform { display: flex; align-items: center; gap: 3px; height: 36px; opacity: 0; transition: opacity .3s; }
.waveform.active { opacity: 1; }
.wave-bar { width: 3px; border-radius: 99px; background: var(--accent); animation: wave .8s ease-in-out infinite; transform-origin: bottom; }
.wave-bar:nth-child(1) { animation-delay:0s; height:12px; }
.wave-bar:nth-child(2) { animation-delay:.1s; height:22px; }
.wave-bar:nth-child(3) { animation-delay:.2s; height:32px; }
.wave-bar:nth-child(4) { animation-delay:.1s; height:20px; }
.wave-bar:nth-child(5) { animation-delay:.3s; height:28px; }
.wave-bar:nth-child(6) { animation-delay:.15s; height:16px; }
.wave-bar:nth-child(7) { animation-delay:.25s; height:24px; }
.wave-bar:nth-child(8) { animation-delay:.05s; height:18px; }
.wave-bar:nth-child(9) { animation-delay:.35s; height:30px; }
.wave-bar:nth-child(10) { animation-delay:.2s; height:14px; }
.recorded-preview { width: 100%; display: none; flex-direction: column; gap: 12px; }
.recorded-preview.visible { display: flex; }
.recorded-preview audio { width: 100%; border-radius: 8px; filter: invert(1) hue-rotate(200deg); }
.recorded-actions { display: flex; gap: 8px; }
.btn-ghost { flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--muted); font-family: 'Syne', sans-serif; font-size: .85rem; cursor: pointer; transition: all .2s; }
.btn-ghost:hover { border-color: var(--text); color: var(--text); }
.submit-btn {
width: 100%; padding: 16px;
background: linear-gradient(135deg, var(--accent), #a855f7);
border: none; border-radius: 12px; color: #fff;
font-family: 'Syne', sans-serif; font-size: 1rem; font-weight: 700;
letter-spacing: .04em; cursor: pointer; transition: all .25s;
display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 8px;
}
.submit-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(124,106,255,.35); }
.submit-btn:active { transform: translateY(0); }
.submit-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
/* ── result card ── */
.result-card { display: none; animation: fadeUp .4s ease both; }
.result-card.visible { display: block; }
.result-inner { display: flex; flex-direction: column; gap: 16px; }
.result-audio-label { font-family: 'JetBrains Mono', monospace; font-size: .75rem; color: var(--success); letter-spacing: .1em; text-transform: uppercase; }
.result-audio audio { width: 100%; border-radius: 8px; filter: invert(1) hue-rotate(130deg); }
.transcript-box {
background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 16px;
font-family: 'JetBrains Mono', monospace; font-size: .82rem; color: var(--text);
line-height: 1.7; white-space: pre-wrap; max-height: 200px; overflow-y: auto;
}
.copy-btn { align-self: flex-end; padding: 8px 16px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--muted); font-family: 'Syne', sans-serif; font-size: .8rem; cursor: pointer; transition: all .2s; }
.copy-btn:hover { color: var(--text); border-color: var(--text); }
/* ── pretty error box ── */
.error-card { display: none; animation: fadeUp .3s ease both; }
.error-card.visible { display: block; }
.error-header {
display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
}
.error-badge {
font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 500;
background: rgba(255,77,106,.15); color: var(--danger);
border: 1px solid rgba(255,77,106,.3); padding: 3px 10px; border-radius: 999px;
letter-spacing: .08em; text-transform: uppercase;
}
.error-title { font-size: .9rem; font-weight: 600; color: var(--danger); }
.error-json {
background: var(--bg); border: 1px solid rgba(255,77,106,.25);
border-radius: 10px; padding: 16px; overflow-x: auto;
font-family: 'JetBrains Mono', monospace; font-size: .8rem; line-height: 1.8;
}
/* JSON syntax highlighting */
.json-key { color: #7c6aff; }
.json-str { color: #4dffb4; }
.json-num { color: #ffb347; }
.json-bool { color: #ff6a9b; }
.json-null { color: #6b6b88; }
.json-brace { color: var(--muted); }
/* ── progress bar ── */
.progress-track { height: 3px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 12px; display: none; }
.progress-track.active { display: block; }
.progress-fill { height: 100%; background: linear-gradient(90deg,var(--accent),#a855f7); border-radius: 99px; width: 0%; transition: width .4s ease; }
/* ── status steps ── */
.status-steps { display: none; flex-direction: column; gap: 6px; margin-top: 12px; }
.status-steps.active { display: flex; }
.status-step {
display: flex; align-items: center; gap: 10px;
font-family: 'JetBrains Mono', monospace; font-size: .75rem; color: var(--muted);
transition: color .3s;
}
.status-step.done { color: var(--success); }
.status-step.active-step { color: var(--accent); }
.step-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.toast { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--surface2); border: 1px solid var(--border); padding: 12px 20px; border-radius: 10px; font-size: .85rem; opacity: 0; transition: all .3s; pointer-events: none; white-space: nowrap; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@keyframes fadeUp { from { opacity:0; transform:translateY(18px); } to { opacity:1; transform:translateY(0); } }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:.4; } }
@keyframes recPulse { 0%,100% { box-shadow:0 0 0 0 rgba(255,77,106,.4); } 50% { box-shadow:0 0 0 14px rgba(255,77,106,0); } }
@keyframes wave { 0%,100% { transform:scaleY(1); } 50% { transform:scaleY(.35); } }
</style>
</head>
<body>
<div class="orb orb-1"></div>
<div class="orb orb-2"></div>
<div class="wrapper">
<header>
<div class="logo-badge"><span></span> CleanVoice AI</div>
<h1>Audio Denoiser</h1>
<p class="subtitle">Remove noise, fillers & stutters from your recordings</p>
</header>
<!-- input card -->
<div class="card">
<div class="card-label">Input Audio</div>
<div class="tabs">
<button class="tab-btn active" data-tab="upload">
<svg width="15" height="15" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
Upload File
</button>
<button class="tab-btn" data-tab="record">
<svg width="15" height="15" fill="none" stroke="currentColor" stroke-width="2" viewBox="0 0 24 24"><path d="M12 2a3 3 0 013 3v7a3 3 0 01-6 0V5a3 3 0 013-3z"/><path d="M19 10v2a7 7 0 01-14 0v-2"/><line x1="12" y1="19" x2="12" y2="22"/></svg>
Record
</button>
</div>
<div class="tab-panel active" id="panel-upload">
<div class="upload-zone" id="dropZone">
<input type="file" id="fileInput" accept="audio/*,.wav,.mp3,.m4a,.ogg,.flac,.webm"/>
<span class="upload-icon">🎡</span>
<p><strong>Drop your audio file here</strong><br>or click to browse</p>
<p class="formats">WAV Β· MP3 Β· M4A Β· OGG Β· FLAC Β· WEBM</p>
</div>
<div class="file-preview" id="filePreview">
<span class="file-icon">🎧</span>
<div class="file-info">
<div class="file-name" id="fileName">β€”</div>
<div class="file-size" id="fileSize">β€”</div>
</div>
<button class="file-remove" id="fileRemove" title="Remove">βœ•</button>
</div>
</div>
<div class="tab-panel" id="panel-record">
<div class="recorder-area">
<div class="waveform" id="waveform">
<div class="wave-bar"></div><div class="wave-bar"></div><div class="wave-bar"></div>
<div class="wave-bar"></div><div class="wave-bar"></div><div class="wave-bar"></div>
<div class="wave-bar"></div><div class="wave-bar"></div><div class="wave-bar"></div>
<div class="wave-bar"></div>
</div>
<button class="record-btn" id="recordBtn"><div class="rec-dot"></div></button>
<div class="rec-timer" id="recTimer">00:00</div>
<div class="rec-status" id="recStatus">tap to record</div>
<div class="recorded-preview" id="recordedPreview">
<audio id="recordedAudio" controls></audio>
<div class="recorded-actions">
<button class="btn-ghost" id="reRecordBtn">β†Ί Re-record</button>
</div>
</div>
</div>
</div>
</div>
<button class="submit-btn" id="submitBtn" disabled>
<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><polygon points="5 3 19 12 5 21 5 3"/></svg>
Process Audio
</button>
<!-- progress -->
<div class="progress-track" id="progressTrack"><div class="progress-fill" id="progressFill"></div></div>
<div class="status-steps" id="statusSteps">
<div class="status-step" id="step1"><div class="step-dot"></div> Uploading audio…</div>
<div class="status-step" id="step2"><div class="step-dot"></div> Converting to WAV…</div>
<div class="status-step" id="step3"><div class="step-dot"></div> Running denoiser…</div>
<div class="status-step" id="step4"><div class="step-dot"></div> Cleaning transcript…</div>
</div>
<!-- result -->
<div class="card result-card" id="resultCard" style="margin-top:24px;">
<div class="card-label">Output</div>
<div class="result-inner">
<div>
<div class="result-audio-label">✦ Cleaned Audio</div>
<div class="result-audio" style="margin-top:10px;"><audio id="resultAudio" controls></audio></div>
</div>
<div>
<div class="result-audio-label" style="color:var(--accent)">✦ Transcript</div>
<div class="transcript-box" id="transcriptBox">β€”</div>
</div>
<button class="copy-btn" id="copyBtn">Copy Transcript</button>
</div>
</div>
<!-- pretty error -->
<div class="card error-card" id="errorCard" style="margin-top:24px; border-color: rgba(255,77,106,.25);">
<div class="card-label" style="color: var(--danger)">Error Response</div>
<div class="error-header">
<span class="error-badge" id="errorStatus">404</span>
<span class="error-title" id="errorTitle">Not Found</span>
</div>
<pre class="error-json" id="errorJson"></pre>
</div>
</div>
<div class="toast" id="toast"></div>
<script>
// ── CONFIG β€” change this to your HF Space API endpoint ──
const API_BASE = 'https://YOUR-HF-SPACE.hf.space'; // e.g. https://yourname-denoiser.hf.space
const DENOISE_ENDPOINT = `${API_BASE}/denoise`; // adjust to your route
/* ──────────────────── TABS ──────────────────── */
document.querySelectorAll('.tab-btn').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
btn.classList.add('active');
document.getElementById('panel-' + btn.dataset.tab).classList.add('active');
clearAudio();
});
});
/* ──────────────────── UPLOAD ──────────────────── */
let uploadedFile = null;
const dropZone = document.getElementById('dropZone');
const fileInput = document.getElementById('fileInput');
const filePreview = document.getElementById('filePreview');
const fileName = document.getElementById('fileName');
const fileSize = document.getElementById('fileSize');
dropZone.addEventListener('click', () => fileInput.click());
dropZone.addEventListener('dragover', e => { e.preventDefault(); dropZone.classList.add('drag-over'); });
dropZone.addEventListener('dragleave', () => dropZone.classList.remove('drag-over'));
dropZone.addEventListener('drop', e => {
e.preventDefault(); dropZone.classList.remove('drag-over');
if (e.dataTransfer.files[0]) setFile(e.dataTransfer.files[0]);
});
fileInput.addEventListener('change', () => { if (fileInput.files[0]) setFile(fileInput.files[0]); });
document.getElementById('fileRemove').addEventListener('click', () => {
uploadedFile = null; filePreview.classList.remove('visible'); updateSubmit();
});
function setFile(f) {
uploadedFile = f;
fileName.textContent = f.name;
fileSize.textContent = (f.size / 1024 / 1024).toFixed(2) + ' MB';
filePreview.classList.add('visible');
updateSubmit();
}
/* ──────────────────── RECORDER ──────────────────── */
let mediaRecorder, recordedBlob, timerInterval, seconds = 0;
const recordBtn = document.getElementById('recordBtn');
const recTimer = document.getElementById('recTimer');
const recStatus = document.getElementById('recStatus');
const waveform = document.getElementById('waveform');
const recordedPreview = document.getElementById('recordedPreview');
const recordedAudio = document.getElementById('recordedAudio');
recordBtn.addEventListener('click', async () => {
if (!mediaRecorder || mediaRecorder.state === 'inactive') {
try {
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
mediaRecorder = new MediaRecorder(stream);
const chunks = [];
mediaRecorder.ondataavailable = e => chunks.push(e.data);
mediaRecorder.onstop = () => {
recordedBlob = new Blob(chunks, { type: 'audio/webm' });
recordedAudio.src = URL.createObjectURL(recordedBlob);
recordedPreview.classList.add('visible');
updateSubmit();
stream.getTracks().forEach(t => t.stop());
};
mediaRecorder.start();
recordBtn.classList.add('recording');
waveform.classList.add('active');
recStatus.textContent = 'recording…'; recStatus.classList.add('live');
seconds = 0; recTimer.textContent = '00:00';
timerInterval = setInterval(() => {
seconds++;
recTimer.textContent = String(Math.floor(seconds/60)).padStart(2,'0') + ':' + String(seconds%60).padStart(2,'0');
}, 1000);
} catch { showToast('Microphone access denied'); }
} else {
mediaRecorder.stop(); clearInterval(timerInterval);
recordBtn.classList.remove('recording'); waveform.classList.remove('active');
recStatus.textContent = 'recording saved'; recStatus.classList.remove('live');
}
});
document.getElementById('reRecordBtn').addEventListener('click', () => {
recordedBlob = null; recordedPreview.classList.remove('visible');
recordedAudio.src = ''; recStatus.textContent = 'tap to record'; recTimer.textContent = '00:00';
updateSubmit();
});
function clearAudio() {
uploadedFile = null; recordedBlob = null;
filePreview.classList.remove('visible'); recordedPreview.classList.remove('visible');
updateSubmit();
}
function updateSubmit() {
document.getElementById('submitBtn').disabled = !(uploadedFile || recordedBlob);
}
/* ──────────────────── PRETTY JSON ──────────────────── */
function syntaxHighlight(obj) {
const json = JSON.stringify(obj, null, 2);
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, match => {
if (/^"/.test(match)) {
if (/:$/.test(match)) return `<span class="json-key">${match}</span>`;
return `<span class="json-str">${match}</span>`;
}
if (/true|false/.test(match)) return `<span class="json-bool">${match}</span>`;
if (/null/.test(match)) return `<span class="json-null">${match}</span>`;
return `<span class="json-num">${match}</span>`;
});
}
function showError(statusCode, data) {
document.getElementById('resultCard').classList.remove('visible');
const card = document.getElementById('errorCard');
const badge = document.getElementById('errorStatus');
const title = document.getElementById('errorTitle');
const jsonEl = document.getElementById('errorJson');
badge.textContent = statusCode;
// derive human title
const titles = { 400:'Bad Request', 401:'Unauthorized', 403:'Forbidden',
404:'Not Found', 422:'Unprocessable Entity', 500:'Internal Server Error' };
title.textContent = data?.detail || titles[statusCode] || 'Error';
jsonEl.innerHTML = syntaxHighlight(data);
card.classList.add('visible');
card.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
/* ──────────────────── PROGRESS ──────────────────── */
function setStep(n) {
[1,2,3,4].forEach(i => {
const el = document.getElementById('step' + i);
el.classList.remove('done','active-step');
if (i < n) el.classList.add('done');
if (i === n) el.classList.add('active-step');
});
document.getElementById('progressFill').style.width = ((n-1)/3 * 100) + '%';
}
function showProgress(show) {
document.getElementById('progressTrack').classList.toggle('active', show);
document.getElementById('statusSteps').classList.toggle('active', show);
if (!show) document.getElementById('progressFill').style.width = '0%';
}
/* ──────────────────── SUBMIT ──────────────────── */
const submitBtn = document.getElementById('submitBtn');
submitBtn.addEventListener('click', async () => {
submitBtn.disabled = true;
submitBtn.innerHTML = `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l4 2"/></svg> Processing…`;
document.getElementById('resultCard').classList.remove('visible');
document.getElementById('errorCard').classList.remove('visible');
showProgress(true);
setStep(1);
const formData = new FormData();
const audioBlob = uploadedFile || recordedBlob;
const audioName = uploadedFile ? uploadedFile.name : 'recording.webm';
formData.append('file', audioBlob, audioName);
try {
setStep(2);
await new Promise(r => setTimeout(r, 400)); // slight delay for UX step visibility
setStep(3);
const response = await fetch(DENOISE_ENDPOINT, {
method: 'POST',
body: formData,
});
const contentType = response.headers.get('Content-Type') || '';
let data;
if (contentType.includes('application/json')) {
data = await response.json();
} else {
data = { detail: await response.text() };
}
if (!response.ok) {
// ── pretty print the error ──
showProgress(false);
showError(response.status, data);
} else {
setStep(4);
// ── happy path: expect { audio_url, transcript } ──
const resultAudio = document.getElementById('resultAudio');
const transcriptBox = document.getElementById('transcriptBox');
const resultCard = document.getElementById('resultCard');
if (data.audio_url) {
resultAudio.src = data.audio_url;
} else if (data.audio_base64) {
resultAudio.src = 'data:audio/wav;base64,' + data.audio_base64;
}
transcriptBox.textContent = data.transcript || data.text || JSON.stringify(data, null, 2);
showProgress(false);
resultCard.classList.add('visible');
resultCard.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
} catch (err) {
showProgress(false);
showError('Network', { detail: err.message, type: 'NetworkError' });
}
submitBtn.disabled = false;
submitBtn.innerHTML = `<svg width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.2" viewBox="0 0 24 24"><polygon points="5 3 19 12 5 21 5 3"/></svg> Process Audio`;
updateSubmit();
});
document.getElementById('copyBtn').addEventListener('click', () => {
navigator.clipboard.writeText(document.getElementById('transcriptBox').textContent)
.then(() => showToast('Copied!'));
});
/* ──────────────────── TOAST ──────────────────── */
const toast = document.getElementById('toast');
function showToast(msg) {
toast.textContent = msg;
toast.classList.add('show');
setTimeout(() => toast.classList.remove('show'), 2500);
}
</script>
</body>
</html>