ui: modernize UI to Mainframe design system
This commit is contained in:
@@ -0,0 +1,488 @@
|
||||
/* ═══════════════════════════════════════════════════════════
|
||||
transcriptionMain.css · Mainframe Design System v3
|
||||
═══════════════════════════════════════════════════════════ */
|
||||
|
||||
:root {
|
||||
--font-heading: 'HelveticaNowDisplay-Medium','Helvetica Neue',Arial,sans-serif;
|
||||
--font-body: 'HelveticaNowDisplayW01-Rg','Helvetica Neue',Arial,sans-serif;
|
||||
--ink: #0a0a0a;
|
||||
--ink-70: rgba(10,10,10,0.70);
|
||||
--ink-45: rgba(10,10,10,0.45);
|
||||
--ink-20: rgba(10,10,10,0.20);
|
||||
--ink-10: rgba(10,10,10,0.10);
|
||||
--ink-05: rgba(10,10,10,0.05);
|
||||
--surface: #f4f3ef;
|
||||
--surface-2: #eeecea;
|
||||
--card: #ffffff;
|
||||
--radius-pill: 9999px;
|
||||
--radius-xl: 24px;
|
||||
--radius-lg: 18px;
|
||||
--radius-md: 12px;
|
||||
--shadow-xs: 0 1px 2px rgba(0,0,0,0.06);
|
||||
--shadow-sm: 0 2px 10px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
|
||||
--shadow-md: 0 6px 28px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.05);
|
||||
--shadow-inset: inset 0 1px 0 rgba(255,255,255,0.8);
|
||||
}
|
||||
|
||||
/* ─── Animations ─────────────────────────────────────────── */
|
||||
@keyframes fade-up {
|
||||
from { opacity:0; transform:translateY(16px); }
|
||||
to { opacity:1; transform:none; }
|
||||
}
|
||||
@keyframes spin { to { transform:rotate(360deg); } }
|
||||
|
||||
/* ─── Base ───────────────────────────────────────────────── */
|
||||
*,*::before,*::after { margin:0; padding:0; box-sizing:border-box; }
|
||||
|
||||
html {
|
||||
font-family: var(--font-body);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
background: var(--surface);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
body {
|
||||
min-height: 100vh;
|
||||
background: var(--surface);
|
||||
padding: 0 20px 100px;
|
||||
font-family: var(--font-body);
|
||||
/* subtle paper grain */
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.028'/%3E%3C/svg%3E");
|
||||
}
|
||||
|
||||
/* ─── Page Layout ────────────────────────────────────────── */
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
padding-top: 48px;
|
||||
}
|
||||
|
||||
/* ─── Upload View ────────────────────────────────────────── */
|
||||
.upload-view {
|
||||
animation: fade-up .7s cubic-bezier(.22,1,.36,1) backwards;
|
||||
animation-delay: .05s;
|
||||
}
|
||||
|
||||
/* ── Section label above heading ── */
|
||||
.upload-view::before {
|
||||
content: '✦ Powered by Whisper AI';
|
||||
display: block;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
letter-spacing: .1em;
|
||||
text-transform: uppercase;
|
||||
color: var(--ink-45);
|
||||
margin-bottom: 14px;
|
||||
padding: 6px 14px;
|
||||
background: var(--card);
|
||||
border: 1px solid var(--ink-10);
|
||||
border-radius: var(--radius-pill);
|
||||
box-shadow: var(--shadow-xs);
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/* ─── Page Heading ───────────────────────────────────────── */
|
||||
.upload-view h1 {
|
||||
font-family: var(--font-heading);
|
||||
font-size: clamp(32px, 6vw, 52px);
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.05em;
|
||||
line-height: 1.0;
|
||||
color: var(--ink);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
/* ─── Subtitle ───────────────────────────────────────────── */
|
||||
.subtitle {
|
||||
font-size: 14px;
|
||||
color: var(--ink-45);
|
||||
line-height: 1.6;
|
||||
margin-bottom: 36px;
|
||||
max-width: 400px;
|
||||
}
|
||||
|
||||
/* ─── Drop Zone ──────────────────────────────────────────── */
|
||||
.upload-area {
|
||||
background: var(--card);
|
||||
border: 1.5px dashed var(--ink-20);
|
||||
border-radius: var(--radius-xl);
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
margin-bottom: 16px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
box-shadow: var(--shadow-sm), var(--shadow-inset);
|
||||
transition:
|
||||
border-color .25s ease,
|
||||
box-shadow .25s ease,
|
||||
transform .25s cubic-bezier(.22,1,.36,1);
|
||||
}
|
||||
|
||||
/* Dashed border via gradient trick for rounded corners */
|
||||
.upload-area::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
border-radius: inherit;
|
||||
background: radial-gradient(ellipse 70% 55% at 50% -10%,
|
||||
rgba(10,10,10,0.04) 0%, transparent 70%);
|
||||
pointer-events: none;
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
/* Inner content wrapper */
|
||||
.upload-area > :not(.file-input) {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
/* Actual click target padding */
|
||||
.upload-area {
|
||||
padding: 52px 32px 44px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.upload-area:hover,
|
||||
.upload-area.dragover {
|
||||
border-color: var(--ink-45);
|
||||
box-shadow: var(--shadow-md), var(--shadow-inset);
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
|
||||
.upload-icon {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 44px; height: 44px;
|
||||
border-radius: var(--radius-md);
|
||||
background: var(--surface-2);
|
||||
border: 1px solid var(--ink-10);
|
||||
box-shadow: var(--shadow-xs);
|
||||
margin-bottom: 16px;
|
||||
font-size: 18px;
|
||||
color: var(--ink-45);
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.upload-area h3 {
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.02em;
|
||||
margin-bottom: 6px;
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
.upload-area p {
|
||||
font-size: 12px;
|
||||
color: var(--ink-45);
|
||||
line-height: 1.55;
|
||||
max-width: 300px;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.file-input { display:none; }
|
||||
|
||||
/* ─── Controls Card ──────────────────────────────────────── */
|
||||
/* Wrap language + model in a subtle grouped container */
|
||||
.language-select,
|
||||
.model-select {
|
||||
animation: fade-up .7s cubic-bezier(.22,1,.36,1) backwards;
|
||||
}
|
||||
|
||||
/* ─── Language Pills ─────────────────────────────────────── */
|
||||
.language-select {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
margin-bottom: 10px;
|
||||
animation-delay: .18s;
|
||||
padding: 14px 16px;
|
||||
background: var(--card);
|
||||
border-radius: var(--radius-lg);
|
||||
border: 1px solid var(--ink-10);
|
||||
box-shadow: var(--shadow-xs);
|
||||
}
|
||||
|
||||
.language-select::before {
|
||||
content: 'Ngôn ngữ';
|
||||
display: block;
|
||||
width: 100%;
|
||||
font-size: 10px;
|
||||
font-weight: 600;
|
||||
letter-spacing: .09em;
|
||||
text-transform: uppercase;
|
||||
color: var(--ink-45);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.language-select label {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 7px;
|
||||
font-size: 13px;
|
||||
letter-spacing: -0.01em;
|
||||
color: var(--ink-70);
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--ink-10);
|
||||
border-radius: var(--radius-pill);
|
||||
padding: 5px 16px;
|
||||
cursor: pointer;
|
||||
box-shadow: var(--shadow-xs);
|
||||
transition: background .18s, color .18s, border-color .18s, box-shadow .18s;
|
||||
user-select: none;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.language-select label:hover {
|
||||
background: var(--ink);
|
||||
color: #fff;
|
||||
border-color: var(--ink);
|
||||
box-shadow: var(--shadow-sm);
|
||||
}
|
||||
|
||||
.language-select input[type="radio"] {
|
||||
accent-color: var(--ink);
|
||||
width: 13px; height: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* ─── Model Row ──────────────────────────────────────────── */
|
||||
.model-select {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 22px;
|
||||
animation-delay: .24s;
|
||||
padding: 12px 16px;
|
||||
background: var(--card);
|
||||
border-radius: var(--radius-lg);
|
||||
border: 1px solid var(--ink-10);
|
||||
box-shadow: var(--shadow-xs);
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
letter-spacing: .06em;
|
||||
text-transform: uppercase;
|
||||
color: var(--ink-45);
|
||||
}
|
||||
|
||||
.model-select select {
|
||||
padding: 6px 14px;
|
||||
border-radius: var(--radius-pill);
|
||||
border: 1px solid var(--ink-10);
|
||||
background: var(--surface);
|
||||
color: var(--ink);
|
||||
font-size: 13px;
|
||||
font-family: var(--font-body);
|
||||
cursor: pointer;
|
||||
appearance: none;
|
||||
-webkit-appearance: none;
|
||||
box-shadow: var(--shadow-xs);
|
||||
transition: border-color .18s, box-shadow .18s;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.model-select select:focus {
|
||||
outline: none;
|
||||
border-color: var(--ink-45);
|
||||
box-shadow: 0 0 0 3px rgba(10,10,10,.07);
|
||||
}
|
||||
|
||||
.model-select select option { background:#fff; color:#000; }
|
||||
|
||||
/* ─── File Info ──────────────────────────────────────────── */
|
||||
.file-info {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--ink-10);
|
||||
border-radius: var(--radius-md);
|
||||
padding: 12px 16px;
|
||||
margin-bottom: 14px;
|
||||
font-size: 12px;
|
||||
color: var(--ink-45);
|
||||
line-height: 1.8;
|
||||
word-break: break-all;
|
||||
display: none;
|
||||
box-shadow: var(--shadow-xs);
|
||||
}
|
||||
|
||||
/* ─── Buttons ────────────────────────────────────────────── */
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 7px;
|
||||
padding: 9px 24px;
|
||||
border-radius: var(--radius-pill);
|
||||
font-size: 13px;
|
||||
font-family: var(--font-body);
|
||||
letter-spacing: -0.01em;
|
||||
cursor: pointer;
|
||||
border: 1px solid var(--ink-10);
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
background: var(--card);
|
||||
color: var(--ink);
|
||||
box-shadow: var(--shadow-xs), var(--shadow-inset);
|
||||
margin: 0 5px 5px 0;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
transition:
|
||||
background .2s ease,
|
||||
color .2s ease,
|
||||
border-color .2s ease,
|
||||
box-shadow .2s ease,
|
||||
transform .18s cubic-bezier(.22,1,.36,1);
|
||||
}
|
||||
|
||||
.btn:hover:not(:disabled) {
|
||||
background: var(--ink);
|
||||
color: #fff;
|
||||
border-color: var(--ink);
|
||||
box-shadow: var(--shadow-md);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.btn:active:not(:disabled) {
|
||||
transform: scale(.97) translateY(0);
|
||||
box-shadow: var(--shadow-xs);
|
||||
}
|
||||
|
||||
.btn:disabled { opacity:.35; cursor:not-allowed; }
|
||||
|
||||
.btn-outline {
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
border-color: var(--ink-20);
|
||||
}
|
||||
.btn-outline:hover:not(:disabled) {
|
||||
background: var(--ink);
|
||||
color: #fff;
|
||||
border-color: var(--ink);
|
||||
box-shadow: var(--shadow-md);
|
||||
}
|
||||
|
||||
/* ─── Progress Card ──────────────────────────────────────── */
|
||||
.progress-container {
|
||||
margin-top: 18px;
|
||||
display: none;
|
||||
background: var(--card);
|
||||
border: 1px solid var(--ink-10);
|
||||
border-radius: var(--radius-xl);
|
||||
padding: 22px 24px 20px;
|
||||
box-shadow: var(--shadow-sm), var(--shadow-inset);
|
||||
animation: fade-up .5s cubic-bezier(.22,1,.36,1) backwards;
|
||||
}
|
||||
|
||||
.progress-container h3 {
|
||||
font-size: 10px;
|
||||
font-weight: 700;
|
||||
letter-spacing: .1em;
|
||||
text-transform: uppercase;
|
||||
color: var(--ink-45);
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
width:100%; height:2px;
|
||||
background: var(--ink-05);
|
||||
border-radius:99px;
|
||||
overflow:hidden;
|
||||
margin-bottom:6px;
|
||||
}
|
||||
.progress-fill {
|
||||
height:100%;
|
||||
background: var(--ink);
|
||||
width:0%;
|
||||
border-radius:99px;
|
||||
transition: width .45s cubic-bezier(.22,1,.36,1);
|
||||
}
|
||||
.upload-progress-bar {
|
||||
width:100%; height:2px;
|
||||
background: var(--ink-05);
|
||||
border-radius:99px;
|
||||
overflow:hidden;
|
||||
margin:10px 0 4px;
|
||||
}
|
||||
.upload-progress-fill {
|
||||
height:100%;
|
||||
background: var(--ink-45);
|
||||
width:0%;
|
||||
border-radius:99px;
|
||||
transition: width .45s cubic-bezier(.22,1,.36,1);
|
||||
}
|
||||
.progress-text {
|
||||
font-size:11px;
|
||||
color:var(--ink-45);
|
||||
margin-top:6px;
|
||||
letter-spacing:.01em;
|
||||
}
|
||||
|
||||
/* ─── Result ─────────────────────────────────────────────── */
|
||||
.result-area {
|
||||
margin-top:22px;
|
||||
display:none;
|
||||
animation: fade-up .5s cubic-bezier(.22,1,.36,1) backwards;
|
||||
}
|
||||
.result-label {
|
||||
font-size:10px;
|
||||
font-weight:700;
|
||||
letter-spacing:.1em;
|
||||
text-transform:uppercase;
|
||||
color:var(--ink-45);
|
||||
margin-bottom:10px;
|
||||
}
|
||||
.result-preview {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--ink-10);
|
||||
border-radius: var(--radius-lg);
|
||||
padding: 16px 20px;
|
||||
font-size:14px;
|
||||
color:var(--ink-70);
|
||||
line-height:1.75;
|
||||
margin-bottom:14px;
|
||||
box-shadow: var(--shadow-xs);
|
||||
}
|
||||
|
||||
/* ─── Transcript View ────────────────────────────────────── */
|
||||
.transcript-view { display:none; }
|
||||
|
||||
.transcript-view h1 {
|
||||
font-family: var(--font-heading);
|
||||
font-size: clamp(26px, 4.5vw, 40px);
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.05em;
|
||||
color: var(--ink);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.meta {
|
||||
font-size: 12px;
|
||||
color: var(--ink-45);
|
||||
margin-bottom: 22px;
|
||||
padding-bottom: 20px;
|
||||
border-bottom: 1px solid var(--ink-10);
|
||||
line-height: 1.9;
|
||||
}
|
||||
.meta strong { color: var(--ink); font-weight: 500; }
|
||||
|
||||
.transcript-content {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--ink-10);
|
||||
border-radius: var(--radius-xl);
|
||||
padding: 26px 28px;
|
||||
font-size:15px;
|
||||
line-height:1.9;
|
||||
white-space:pre-wrap;
|
||||
word-wrap:break-word;
|
||||
max-height:580px;
|
||||
overflow-y:auto;
|
||||
color:var(--ink-70);
|
||||
box-shadow: var(--shadow-sm), var(--shadow-inset);
|
||||
scrollbar-width:thin;
|
||||
scrollbar-color: var(--ink-10) transparent;
|
||||
}
|
||||
.transcript-content::-webkit-scrollbar { width:4px; }
|
||||
.transcript-content::-webkit-scrollbar-track { background:transparent; }
|
||||
.transcript-content::-webkit-scrollbar-thumb { background:var(--ink-10); border-radius:99px; }
|
||||
|
||||
.nav-buttons { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:22px; }
|
||||
@@ -0,0 +1,286 @@
|
||||
if (document.querySelector(".upload-view").style.display !== "none") {
|
||||
const uploadArea = document.getElementById("uploadArea");
|
||||
const fileInput = document.getElementById("fileInput");
|
||||
const uploadBtn = document.getElementById("uploadBtn");
|
||||
const fileInfo = document.getElementById("fileInfo");
|
||||
const progressContainer = document.getElementById("progressContainer");
|
||||
const progressFill = document.getElementById("progressFill");
|
||||
const uploadProgressFill =
|
||||
document.getElementById("uploadProgressFill");
|
||||
const progressText = document.getElementById("progressText");
|
||||
const resultArea = document.getElementById("resultArea");
|
||||
const transcriptPreview = document.getElementById("transcriptPreview");
|
||||
let selectedFile = null;
|
||||
|
||||
uploadArea.addEventListener("click", () => fileInput.click());
|
||||
uploadArea.addEventListener("dragover", (e) => {
|
||||
e.preventDefault();
|
||||
uploadArea.classList.add("dragover");
|
||||
});
|
||||
uploadArea.addEventListener("dragleave", () =>
|
||||
uploadArea.classList.remove("dragover"),
|
||||
);
|
||||
uploadArea.addEventListener("drop", (e) => {
|
||||
e.preventDefault();
|
||||
uploadArea.classList.remove("dragover");
|
||||
if (e.dataTransfer.files.length > 0)
|
||||
handleFileSelect(e.dataTransfer.files[0]);
|
||||
});
|
||||
fileInput.addEventListener("change", (e) => {
|
||||
if (e.target.files.length > 0) handleFileSelect(e.target.files[0]);
|
||||
});
|
||||
|
||||
function handleFileSelect(file) {
|
||||
selectedFile = file;
|
||||
const sizeInMB = (file.size / (1024 * 1024)).toFixed(2);
|
||||
fileInfo.style.display = "block";
|
||||
fileInfo.innerHTML = `<strong>Tệp đã chọn:</strong> ${file.name}<br><strong>Kích thước:</strong> ${sizeInMB} MB`;
|
||||
uploadBtn.style.display = "inline-block";
|
||||
}
|
||||
|
||||
uploadBtn.addEventListener("click", async () => {
|
||||
if (!selectedFile) return;
|
||||
|
||||
const language = document.querySelector(
|
||||
'input[name="language"]:checked',
|
||||
).value;
|
||||
const model = document.getElementById("modelSelect").value;
|
||||
|
||||
uploadBtn.disabled = true;
|
||||
progressContainer.style.display = "block";
|
||||
resultArea.style.display = "none";
|
||||
|
||||
try {
|
||||
await uploadFileInChunks(selectedFile, language, model);
|
||||
} catch (error) {
|
||||
alert("Tải lên thất bại: " + error.message);
|
||||
uploadBtn.disabled = false;
|
||||
progressContainer.style.display = "none";
|
||||
}
|
||||
});
|
||||
|
||||
async function uploadFileInChunks(file, language, model) {
|
||||
const CHUNK_SIZE = 3 * 60 * 1000; // 3 minutes in milliseconds
|
||||
let jobId = null;
|
||||
|
||||
// Create audio context to get duration
|
||||
const audioContext = new (
|
||||
window.AudioContext || window.webkitAudioContext
|
||||
)();
|
||||
const arrayBuffer = await file.arrayBuffer();
|
||||
const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
|
||||
const duration = audioBuffer.duration * 1000; // Duration in milliseconds
|
||||
|
||||
const totalChunks = Math.ceil(duration / CHUNK_SIZE);
|
||||
progressText.textContent = `Đang chuẩn bị tải lên ${totalChunks} phần...`;
|
||||
|
||||
for (let i = 0; i < totalChunks; i++) {
|
||||
const start = i * CHUNK_SIZE;
|
||||
const end = Math.min(start + CHUNK_SIZE, duration);
|
||||
|
||||
progressText.textContent = `Đang tải lên phần ${i + 1}/${totalChunks}...`;
|
||||
|
||||
// Extract chunk from audio
|
||||
const chunkBlob = await extractAudioChunk(
|
||||
audioBuffer,
|
||||
start,
|
||||
end,
|
||||
file.type,
|
||||
);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("chunk", chunkBlob, `chunk_${i}.mp3`);
|
||||
formData.append("chunk_index", i);
|
||||
formData.append("total_chunks", totalChunks);
|
||||
formData.append("filename", file.name);
|
||||
formData.append("language", language);
|
||||
formData.append("model", model);
|
||||
|
||||
if (jobId) {
|
||||
formData.append("job_id", jobId);
|
||||
}
|
||||
|
||||
const response = await fetch("/upload-chunk", {
|
||||
method: "POST",
|
||||
body: formData,
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || "Upload failed");
|
||||
}
|
||||
|
||||
jobId = data.job_id;
|
||||
|
||||
// Update upload progress
|
||||
const uploadProgress = ((i + 1) / totalChunks) * 100;
|
||||
uploadProgressFill.style.width = uploadProgress + "%";
|
||||
|
||||
if (data.status === "processing") {
|
||||
progressText.textContent =
|
||||
"Tất cả các phần đã được tải lên! Đang bắt đầu phiên âm...";
|
||||
startPolling(jobId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function extractAudioChunk(
|
||||
audioBuffer,
|
||||
startTime,
|
||||
endTime,
|
||||
mimeType,
|
||||
) {
|
||||
const sampleRate = audioBuffer.sampleRate;
|
||||
const startSample = Math.floor((startTime * sampleRate) / 1000);
|
||||
const endSample = Math.floor((endTime * sampleRate) / 1000);
|
||||
const frameCount = endSample - startSample;
|
||||
|
||||
// Create new audio buffer for chunk
|
||||
const chunkBuffer = new AudioContext().createBuffer(
|
||||
audioBuffer.numberOfChannels,
|
||||
frameCount,
|
||||
sampleRate,
|
||||
);
|
||||
|
||||
// Copy data
|
||||
for (
|
||||
let channel = 0;
|
||||
channel < audioBuffer.numberOfChannels;
|
||||
channel++
|
||||
) {
|
||||
const channelData = audioBuffer.getChannelData(channel);
|
||||
const chunkData = chunkBuffer.getChannelData(channel);
|
||||
for (let i = 0; i < frameCount; i++) {
|
||||
chunkData[i] = channelData[startSample + i];
|
||||
}
|
||||
}
|
||||
|
||||
// Convert to WAV first, then let server handle conversion
|
||||
const wavBlob = audioBufferToWav(chunkBuffer);
|
||||
|
||||
// If it's already an audio file, return as is, otherwise convert
|
||||
if (mimeType.includes("audio")) {
|
||||
return wavBlob;
|
||||
} else {
|
||||
// For video files, we'll send the audio portion
|
||||
return wavBlob;
|
||||
}
|
||||
}
|
||||
|
||||
function audioBufferToWav(buffer) {
|
||||
const numChannels = buffer.numberOfChannels;
|
||||
const sampleRate = buffer.sampleRate;
|
||||
const format = 1; // PCM
|
||||
const bitDepth = 16;
|
||||
|
||||
let resultBuffer;
|
||||
|
||||
if (numChannels === 2) {
|
||||
resultBuffer = interleave(
|
||||
buffer.getChannelData(0),
|
||||
buffer.getChannelData(1),
|
||||
);
|
||||
} else {
|
||||
resultBuffer = buffer.getChannelData(0);
|
||||
}
|
||||
|
||||
const dataLength = resultBuffer.length * 2;
|
||||
const bufferLength = 44 + dataLength;
|
||||
const arrayBuffer = new ArrayBuffer(bufferLength);
|
||||
const view = new DataView(arrayBuffer);
|
||||
|
||||
// Write WAV header
|
||||
writeString(view, 0, "RIFF");
|
||||
view.setUint32(4, 36 + dataLength, true);
|
||||
writeString(view, 8, "WAVE");
|
||||
writeString(view, 12, "fmt ");
|
||||
view.setUint32(16, 16, true);
|
||||
view.setUint16(20, format, true);
|
||||
view.setUint16(22, numChannels, true);
|
||||
view.setUint32(24, sampleRate, true);
|
||||
view.setUint32(28, sampleRate * 4, true);
|
||||
view.setUint16(32, numChannels * 2, true);
|
||||
view.setUint16(34, bitDepth, true);
|
||||
writeString(view, 36, "data");
|
||||
view.setUint32(40, dataLength, true);
|
||||
|
||||
// Write audio data
|
||||
const offset = 44;
|
||||
for (let i = 0; i < resultBuffer.length; i++) {
|
||||
const sample = Math.max(-1, Math.min(1, resultBuffer[i]));
|
||||
view.setInt16(
|
||||
offset + i * 2,
|
||||
sample < 0 ? sample * 0x8000 : sample * 0x7fff,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
return new Blob([arrayBuffer], { type: "audio/wav" });
|
||||
}
|
||||
|
||||
function writeString(view, offset, string) {
|
||||
for (let i = 0; i < string.length; i++) {
|
||||
view.setUint8(offset + i, string.charCodeAt(i));
|
||||
}
|
||||
}
|
||||
|
||||
function interleave(left, right) {
|
||||
const length = left.length + right.length;
|
||||
const result = new Float32Array(length);
|
||||
|
||||
let inputIndex = 0;
|
||||
for (let i = 0; i < length; i += 2) {
|
||||
result[i] = left[inputIndex];
|
||||
result[i + 1] = right[inputIndex];
|
||||
inputIndex++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function startPolling(jobId) {
|
||||
const pollInterval = setInterval(async () => {
|
||||
try {
|
||||
const data = await (await fetch(`/status/${jobId}`)).json();
|
||||
progressFill.style.width = data.progress + "%";
|
||||
|
||||
if (data.status === "processing") {
|
||||
progressText.textContent = data.current_chunk
|
||||
? `Đang phiên âm đoạn ${data.current_chunk}...`
|
||||
: `Đang xử lý: ${data.progress}%`;
|
||||
} else if (data.status === "completed") {
|
||||
clearInterval(pollInterval);
|
||||
progressText.textContent = "Hoàn tất!";
|
||||
showResult(jobId);
|
||||
} else if (data.status === "error") {
|
||||
clearInterval(pollInterval);
|
||||
progressText.textContent = "Lỗi: " + data.error;
|
||||
uploadBtn.disabled = false;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Lỗi kiểm tra:", e);
|
||||
}
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
async function showResult(jobId) {
|
||||
try {
|
||||
const html = await (await fetch(`/view/${jobId}`)).text();
|
||||
const doc = new DOMParser().parseFromString(html, "text/html");
|
||||
const content =
|
||||
doc.querySelector(".transcript-content")?.textContent ||
|
||||
"Đã tải bản phiên âm";
|
||||
transcriptPreview.innerHTML = `<pre style="white-space:pre-wrap;word-wrap:break-word;margin:0;font-family:inherit">${content.substring(0, 300)}...</pre>`;
|
||||
resultArea.style.display = "block";
|
||||
uploadBtn.disabled = false;
|
||||
document.getElementById("viewFullBtn").onclick = () =>
|
||||
window.open(`/view/${jobId}`, "_blank");
|
||||
document.getElementById("downloadBtn").onclick = () =>
|
||||
(window.location.href = `/transcript/${jobId}`);
|
||||
} catch (e) {
|
||||
console.error("Lỗi hiển thị:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
/* ═══════════════════════════════════════════════════════════
|
||||
transcriptionReview.css · Mainframe Design System v3
|
||||
═══════════════════════════════════════════════════════════ */
|
||||
|
||||
:root {
|
||||
--font-heading: 'HelveticaNowDisplay-Medium','Helvetica Neue',Arial,sans-serif;
|
||||
--font-body: 'HelveticaNowDisplayW01-Rg','Helvetica Neue',Arial,sans-serif;
|
||||
--ink: #0a0a0a;
|
||||
--ink-70: rgba(10,10,10,0.70);
|
||||
--ink-45: rgba(10,10,10,0.45);
|
||||
--ink-20: rgba(10,10,10,0.20);
|
||||
--ink-10: rgba(10,10,10,0.10);
|
||||
--ink-05: rgba(10,10,10,0.05);
|
||||
--surface: #f4f3ef;
|
||||
--card: #ffffff;
|
||||
--radius-pill: 9999px;
|
||||
--radius-xl: 24px;
|
||||
--radius-lg: 18px;
|
||||
--shadow-xs: 0 1px 2px rgba(0,0,0,0.06);
|
||||
--shadow-sm: 0 2px 10px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
|
||||
--shadow-md: 0 6px 28px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.05);
|
||||
--shadow-inset: inset 0 1px 0 rgba(255,255,255,0.8);
|
||||
}
|
||||
|
||||
@keyframes fade-up {
|
||||
from { opacity:0; transform:translateY(14px); }
|
||||
to { opacity:1; transform:none; }
|
||||
}
|
||||
|
||||
*,*::before,*::after { margin:0; padding:0; box-sizing:border-box; }
|
||||
|
||||
html {
|
||||
font-family: var(--font-body);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
background: var(--surface);
|
||||
color: var(--ink);
|
||||
}
|
||||
|
||||
body {
|
||||
min-height: 100vh;
|
||||
background: var(--surface);
|
||||
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='0.028'/%3E%3C/svg%3E");
|
||||
padding: 0 20px 100px;
|
||||
font-family: var(--font-body);
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: 820px;
|
||||
margin: 0 auto;
|
||||
padding-top: 48px;
|
||||
animation: fade-up .7s cubic-bezier(.22,1,.36,1) backwards;
|
||||
animation-delay: .05s;
|
||||
}
|
||||
|
||||
/* ─── Eyebrow label above h1 ─────────────────────────────── */
|
||||
.container::before {
|
||||
content: '✦ Kết quả phiên âm';
|
||||
display: inline-block;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
letter-spacing: .1em;
|
||||
text-transform: uppercase;
|
||||
color: var(--ink-45);
|
||||
margin-bottom: 14px;
|
||||
padding: 6px 14px;
|
||||
background: var(--card);
|
||||
border: 1px solid var(--ink-10);
|
||||
border-radius: var(--radius-pill);
|
||||
box-shadow: var(--shadow-xs);
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-family: var(--font-heading);
|
||||
font-size: clamp(28px, 5vw, 42px);
|
||||
font-weight: 500;
|
||||
letter-spacing: -0.05em;
|
||||
line-height: 1.0;
|
||||
color: var(--ink);
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.meta {
|
||||
font-size: 12px;
|
||||
color: var(--ink-45);
|
||||
line-height: 2;
|
||||
margin-bottom: 24px;
|
||||
padding: 14px 18px;
|
||||
background: var(--card);
|
||||
border: 1px solid var(--ink-10);
|
||||
border-radius: var(--radius-lg);
|
||||
box-shadow: var(--shadow-xs);
|
||||
}
|
||||
.meta strong { color: var(--ink); font-weight: 500; }
|
||||
|
||||
/* Nav row */
|
||||
div[style*="margin-bottom"] {
|
||||
display: flex !important;
|
||||
gap: 6px !important;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 22px !important;
|
||||
}
|
||||
|
||||
/* ─── Buttons ────────────────────────────────────────────── */
|
||||
.btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 7px;
|
||||
padding: 9px 24px;
|
||||
border-radius: var(--radius-pill);
|
||||
font-size: 13px;
|
||||
font-family: var(--font-body);
|
||||
letter-spacing: -0.01em;
|
||||
cursor: pointer;
|
||||
border: 1px solid var(--ink-10);
|
||||
text-decoration: none;
|
||||
white-space: nowrap;
|
||||
background: var(--card);
|
||||
color: var(--ink);
|
||||
box-shadow: var(--shadow-xs), var(--shadow-inset);
|
||||
margin: 0 5px 5px 0;
|
||||
transition: background .2s, color .2s, border-color .2s, box-shadow .2s,
|
||||
transform .18s cubic-bezier(.22,1,.36,1);
|
||||
}
|
||||
.btn:hover:not(:disabled) {
|
||||
background: var(--ink);
|
||||
color: #fff;
|
||||
border-color: var(--ink);
|
||||
box-shadow: var(--shadow-md);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
.btn:active:not(:disabled) { transform: scale(.97); box-shadow: var(--shadow-xs); }
|
||||
.btn:disabled { opacity:.36; cursor:not-allowed; }
|
||||
|
||||
/* ─── Transcript body ────────────────────────────────────── */
|
||||
.transcript {
|
||||
background: var(--card);
|
||||
border: 1px solid var(--ink-10);
|
||||
border-radius: var(--radius-xl);
|
||||
padding: 28px 30px;
|
||||
font-size: 15px;
|
||||
line-height: 1.95;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
color: var(--ink-70);
|
||||
box-shadow: var(--shadow-sm), var(--shadow-inset);
|
||||
animation: fade-up .7s cubic-bezier(.22,1,.36,1) backwards;
|
||||
animation-delay: .18s;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: var(--ink-10) transparent;
|
||||
}
|
||||
.transcript::-webkit-scrollbar { width:4px; }
|
||||
.transcript::-webkit-scrollbar-track { background:transparent; }
|
||||
.transcript::-webkit-scrollbar-thumb { background:var(--ink-10); border-radius:99px; }
|
||||
@@ -0,0 +1,3 @@
|
||||
// transcriptionReview.js
|
||||
// Custom JavaScript for Transcription Review
|
||||
console.log("Transcription Review initialized.");
|
||||
Reference in New Issue
Block a user