Spaces:
Running
Running
Update index.html
Browse files- index.html +63 -111
index.html
CHANGED
|
@@ -3,37 +3,34 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
-
<title>μμ± λ²μκΈ° (
|
| 7 |
<style>
|
| 8 |
body { font-family: "λ§μ κ³ λ", sans-serif; max-width: 720px; margin: 24px auto; padding: 0 16px; color: #202124; }
|
| 9 |
h1 { font-size: 24px; margin-bottom: 4px; }
|
| 10 |
.sub { color: #5f6368; margin-top: 0; }
|
| 11 |
-
#status { display: block; margin: 12px 0; padding: 8px 12px; background: #
|
| 12 |
textarea { width: 100%; height: 90px; font-size: 15px; padding: 8px; box-sizing: border-box; resize: none; }
|
| 13 |
.box { margin-top: 16px; }
|
| 14 |
h3 { font-size: 16px; margin-bottom: 8px; }
|
| 15 |
-
.input-row { display: flex; align-items: center; gap: 12px; margin: 16px 0;
|
| 16 |
#record-btn { padding: 8px 16px; font-size: 14px; cursor: pointer; border: 1px solid #dadce0; background: white; border-radius: 4px; transition: 0.2s; }
|
| 17 |
#record-btn.recording { background-color: #fce8e6; color: #d93025; border-color: #d93025; font-weight: bold; animation: blink 1s infinite; }
|
| 18 |
@keyframes blink { 50% { opacity: 0.7; } }
|
| 19 |
-
.divider { color: #5f6368; font-size: 14px; }
|
| 20 |
</style>
|
| 21 |
</head>
|
| 22 |
<body>
|
| 23 |
-
<h1>μμ± λ²μκΈ° β‘
|
| 24 |
-
<p class="sub">νκ΅μ΄λ‘ λ§νλ©΄
|
| 25 |
|
| 26 |
<div class="input-row">
|
| 27 |
<button id="record-btn">π€ λ
Ήμ μμ</button>
|
| 28 |
-
<span class="divider">λλ μμ± νμΌ:</span>
|
| 29 |
-
<input id="upload" type="file" accept="audio/*" />
|
| 30 |
</div>
|
| 31 |
|
| 32 |
-
<span id="status">λͺ¨λΈ λΆλ¬μ€λ μ€... (
|
| 33 |
|
| 34 |
<div class="box">
|
| 35 |
<h3>β μμλ€μ νκ΅μ΄</h3>
|
| 36 |
-
<textarea id="korean-text" readonly placeholder="μ¬κΈ°μ
|
| 37 |
</div>
|
| 38 |
|
| 39 |
<div class="box">
|
|
@@ -44,145 +41,100 @@
|
|
| 44 |
<script type="module">
|
| 45 |
import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.6";
|
| 46 |
|
| 47 |
-
//
|
| 48 |
-
const
|
| 49 |
-
const SPEECH_LANGUAGE = "korean";
|
| 50 |
-
const TRANSLATE_MODEL = "Xenova/opus-mt-ko-en";
|
| 51 |
-
const MAX_SECONDS = 30; // λ
Ήμ μ΅λ κΈΈμ΄(μ΄)[cite: 1]
|
| 52 |
|
| 53 |
const statusBox = document.getElementById("status");
|
| 54 |
-
const uploadInput = document.getElementById("upload");
|
| 55 |
const recordBtn = document.getElementById("record-btn");
|
| 56 |
const koreanBox = document.getElementById("korean-text");
|
| 57 |
const englishBox = document.getElementById("english-text");
|
| 58 |
|
| 59 |
-
let transcriber = null;
|
| 60 |
let translator = null;
|
| 61 |
let loadSeconds = "";
|
| 62 |
|
| 63 |
-
// 1. λͺ¨λΈ
|
| 64 |
async function loadModels() {
|
| 65 |
try {
|
| 66 |
const loadStart = performance.now();
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
statusBox.textContent = `
|
| 70 |
}
|
| 71 |
-
};
|
| 72 |
-
|
| 73 |
-
// λ³λ ¬ λ‘λ©μΌλ‘ μλ κ·Ήλν
|
| 74 |
-
[transcriber, translator] = await Promise.all([
|
| 75 |
-
pipeline("automatic-speech-recognition", SPEECH_MODEL, { progress_callback: progressCallback }),
|
| 76 |
-
pipeline("translation", TRANSLATE_MODEL, { progress_callback: progressCallback })
|
| 77 |
-
]);
|
| 78 |
-
|
| 79 |
loadSeconds = ((performance.now() - loadStart) / 1000).toFixed(1);
|
| 80 |
-
statusBox.textContent = `β
μ€λΉ μλ£
|
| 81 |
statusBox.style.color = "#0f9d58";
|
| 82 |
} catch (error) {
|
| 83 |
-
statusBox.textContent = `β λͺ¨λΈ
|
| 84 |
statusBox.style.color = "#d93025";
|
| 85 |
}
|
| 86 |
}
|
| 87 |
loadModels();
|
| 88 |
|
| 89 |
-
// 2. μ
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
return;
|
| 94 |
-
}
|
| 95 |
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
koreanBox.value = "";
|
| 100 |
englishBox.value = "";
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
const
|
| 105 |
-
const asrResult = await transcriber(audioUrl, {
|
| 106 |
-
language: SPEECH_LANGUAGE,
|
| 107 |
-
task: "transcribe"
|
| 108 |
-
});
|
| 109 |
-
const koreanText = asrResult.text.trim();
|
| 110 |
-
const asrSeconds = ((performance.now() - asrStart) / 1000).toFixed(1);
|
| 111 |
koreanBox.value = koreanText;
|
|
|
|
|
|
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
}
|
| 124 |
-
statusBox.textContent = `β μ€ν μ€ μ€λ₯ λ°μ : ${error.message}`;
|
| 125 |
-
statusBox.style.color = "#d93025";
|
| 126 |
-
}
|
| 127 |
-
}
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
|
|
|
| 139 |
|
| 140 |
function stopRecording() {
|
| 141 |
-
if (
|
| 142 |
-
|
| 143 |
}
|
| 144 |
isRecording = false;
|
| 145 |
-
clearTimeout(recordingTimeout);
|
| 146 |
recordBtn.textContent = "π€ λ
Ήμ μμ";
|
| 147 |
recordBtn.classList.remove("recording");
|
| 148 |
}
|
| 149 |
|
| 150 |
-
recordBtn.addEventListener("click",
|
| 151 |
-
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
| 152 |
-
alert("νμ¬ λΈλΌμ°μ μμ λ§μ΄ν¬λ₯Ό μ§μνμ§ μκ±°λ κΆνμ΄ μ°¨λ¨λμ΄ μμ΅λλ€.\nμ€μ μμ λ§μ΄ν¬ κΆνμ νμ©ν΄μ£ΌμΈμ.");
|
| 153 |
-
return;
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
if (!isRecording) {
|
| 157 |
-
|
| 158 |
-
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 159 |
-
mediaRecorder = new MediaRecorder(stream);
|
| 160 |
-
audioChunks = [];
|
| 161 |
-
|
| 162 |
-
mediaRecorder.ondataavailable = (e) => {
|
| 163 |
-
if (e.data.size > 0) audioChunks.push(e.data);
|
| 164 |
-
};
|
| 165 |
-
|
| 166 |
-
mediaRecorder.onstop = () => {
|
| 167 |
-
const audioBlob = new Blob(audioChunks);
|
| 168 |
-
processAudioData(audioBlob);
|
| 169 |
-
stream.getTracks().forEach(track => track.stop());
|
| 170 |
-
};
|
| 171 |
-
|
| 172 |
-
mediaRecorder.start();
|
| 173 |
-
isRecording = true;
|
| 174 |
-
recordBtn.textContent = "βΉοΈ λ
Ήμ μ€μ§";
|
| 175 |
-
recordBtn.classList.add("recording");
|
| 176 |
-
statusBox.textContent = `ποΈ λ
Ήμ μ€... (μ΅λ ${MAX_SECONDS}μ΄)`;[cite: 1]
|
| 177 |
-
statusBox.style.color = "#d93025";
|
| 178 |
-
|
| 179 |
-
recordingTimeout = setTimeout(() => {
|
| 180 |
-
if (isRecording) stopRecording();
|
| 181 |
-
}, MAX_SECONDS * 1000);[cite: 1]
|
| 182 |
-
|
| 183 |
-
} catch (err) {
|
| 184 |
-
alert(`λ§μ΄ν¬ μ κ·Ό μ€λ₯: ${err.message}\nλΈλΌμ°μ μ€μ μμ λ§μ΄ν¬ κΆνμ νμ©ν΄ μ£ΌμΈμ.`);
|
| 185 |
-
}
|
| 186 |
} else {
|
| 187 |
stopRecording();
|
| 188 |
}
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8" />
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>μμ± λ²μκΈ° (μ¦μ μ€ν λͺ¨λ)</title>
|
| 7 |
<style>
|
| 8 |
body { font-family: "λ§μ κ³ λ", sans-serif; max-width: 720px; margin: 24px auto; padding: 0 16px; color: #202124; }
|
| 9 |
h1 { font-size: 24px; margin-bottom: 4px; }
|
| 10 |
.sub { color: #5f6368; margin-top: 0; }
|
| 11 |
+
#status { display: block; margin: 12px 0; padding: 8px 12px; background: #e8f0fe; border-radius: 6px; font-weight: bold; color: #1a73e8; }
|
| 12 |
textarea { width: 100%; height: 90px; font-size: 15px; padding: 8px; box-sizing: border-box; resize: none; }
|
| 13 |
.box { margin-top: 16px; }
|
| 14 |
h3 { font-size: 16px; margin-bottom: 8px; }
|
| 15 |
+
.input-row { display: flex; align-items: center; gap: 12px; margin: 16px 0; }
|
| 16 |
#record-btn { padding: 8px 16px; font-size: 14px; cursor: pointer; border: 1px solid #dadce0; background: white; border-radius: 4px; transition: 0.2s; }
|
| 17 |
#record-btn.recording { background-color: #fce8e6; color: #d93025; border-color: #d93025; font-weight: bold; animation: blink 1s infinite; }
|
| 18 |
@keyframes blink { 50% { opacity: 0.7; } }
|
|
|
|
| 19 |
</style>
|
| 20 |
</head>
|
| 21 |
<body>
|
| 22 |
+
<h1>μμ± λ²μκΈ° β‘μ¦μ μ€ν λͺ¨λ</h1>
|
| 23 |
+
<p class="sub">νκ΅μ΄λ‘ λ§νλ©΄ λΈλΌμ°μ λ΄μ₯ APIλ‘ μ¦μ μΈμνκ³ λ²μν΄ μ€λλ€.</p>
|
| 24 |
|
| 25 |
<div class="input-row">
|
| 26 |
<button id="record-btn">π€ λ
Ήμ μμ</button>
|
|
|
|
|
|
|
| 27 |
</div>
|
| 28 |
|
| 29 |
+
<span id="status">λ²μ λͺ¨λΈ λΆλ¬μ€λ μ€... (μ½ 70MB)</span>
|
| 30 |
|
| 31 |
<div class="box">
|
| 32 |
<h3>β μμλ€μ νκ΅μ΄</h3>
|
| 33 |
+
<textarea id="korean-text" readonly placeholder="λ§μνμλ©΄ μ¬κΈ°μ μ¦μ νμλ©λλ€."></textarea>
|
| 34 |
</div>
|
| 35 |
|
| 36 |
<div class="box">
|
|
|
|
| 41 |
<script type="module">
|
| 42 |
import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.6";
|
| 43 |
|
| 44 |
+
// STT λͺ¨λΈμ μ μΈνκ³ λ²μ λͺ¨λΈλ§ λ‘λνμ¬ μλ κ·Ήλν
|
| 45 |
+
const TRANSLATE_MODEL = "Xenova/opus-mt-ko-en";[cite: 1]
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
const statusBox = document.getElementById("status");
|
|
|
|
| 48 |
const recordBtn = document.getElementById("record-btn");
|
| 49 |
const koreanBox = document.getElementById("korean-text");
|
| 50 |
const englishBox = document.getElementById("english-text");
|
| 51 |
|
|
|
|
| 52 |
let translator = null;
|
| 53 |
let loadSeconds = "";
|
| 54 |
|
| 55 |
+
// 1. λ²μ λͺ¨λΈλ§ λ‘λ
|
| 56 |
async function loadModels() {
|
| 57 |
try {
|
| 58 |
const loadStart = performance.now();
|
| 59 |
+
translator = await pipeline("translation", TRANSLATE_MODEL, {
|
| 60 |
+
progress_callback: data => {
|
| 61 |
+
if (data.status === 'progress') statusBox.textContent = `λ²μ λͺ¨λΈ λ€μ΄λ‘λ μ€... ${Math.round(data.progress)}%`;
|
| 62 |
}
|
| 63 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
loadSeconds = ((performance.now() - loadStart) / 1000).toFixed(1);
|
| 65 |
+
statusBox.textContent = `β
μ€λΉ μλ£ (λ²μ λ‘λ©: ${loadSeconds}μ΄)`;
|
| 66 |
statusBox.style.color = "#0f9d58";
|
| 67 |
} catch (error) {
|
| 68 |
+
statusBox.textContent = `β λͺ¨λΈ λ‘λ μ€ν¨: ${error.message}`;
|
| 69 |
statusBox.style.color = "#d93025";
|
| 70 |
}
|
| 71 |
}
|
| 72 |
loadModels();
|
| 73 |
|
| 74 |
+
// 2. λΈλΌμ°μ λ΄μ₯ Web Speech API μ€μ (λ€μ΄λ‘λ μμ, μ¦μ μΈμ)
|
| 75 |
+
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
| 76 |
+
let recognition;
|
| 77 |
+
let isRecording = false;
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
if (SpeechRecognition) {
|
| 80 |
+
recognition = new SpeechRecognition();
|
| 81 |
+
recognition.lang = 'ko-KR';
|
| 82 |
+
recognition.interimResults = false;
|
| 83 |
+
recognition.maxAlternatives = 1;
|
| 84 |
+
|
| 85 |
+
recognition.onstart = () => {
|
| 86 |
+
isRecording = true;
|
| 87 |
+
recordBtn.textContent = "βΉοΈ λ
Ήμ μ€μ§";
|
| 88 |
+
recordBtn.classList.add("recording");
|
| 89 |
+
statusBox.textContent = "ποΈ λ£κ³ μμ΅λλ€...";
|
| 90 |
+
statusBox.style.color = "#d93025";
|
| 91 |
koreanBox.value = "";
|
| 92 |
englishBox.value = "";
|
| 93 |
+
};
|
| 94 |
|
| 95 |
+
// μμ± μΈμμ΄ μλ£λμμ λ
|
| 96 |
+
recognition.onresult = async (event) => {
|
| 97 |
+
const koreanText = event.results[0][0].transcript;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
koreanBox.value = koreanText;
|
| 99 |
+
statusBox.textContent = "π λ²μνλ μ€...";
|
| 100 |
+
statusBox.style.color = "#1a73e8";
|
| 101 |
|
| 102 |
+
if (translator) {
|
| 103 |
+
const transStart = performance.now();
|
| 104 |
+
const transResult = await translator(koreanText);
|
| 105 |
+
const transSeconds = ((performance.now() - transStart) / 1000).toFixed(1);
|
| 106 |
+
englishBox.value = transResult[0].translation_text;
|
| 107 |
+
statusBox.textContent = `β¨ μλ£ Β· (λ²μ μμμκ°: ${transSeconds}μ΄)`;
|
| 108 |
+
statusBox.style.color = "#0f9d58";
|
| 109 |
+
} else {
|
| 110 |
+
statusBox.textContent = "β λ²μ λͺ¨λΈμ΄ μμ§ λ‘λλμ§ μμμ΅λλ€.";
|
| 111 |
+
}
|
| 112 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
|
| 114 |
+
recognition.onerror = (event) => {
|
| 115 |
+
statusBox.textContent = `β μμ± μΈμ μ€λ₯: ${event.error}`;
|
| 116 |
+
stopRecording();
|
| 117 |
+
};
|
| 118 |
|
| 119 |
+
recognition.onend = () => {
|
| 120 |
+
if (isRecording) stopRecording();
|
| 121 |
+
};
|
| 122 |
+
} else {
|
| 123 |
+
alert("μ΄ λΈλΌμ°μ λ Web Speech APIλ₯Ό μ§μνμ§ μμ΅λλ€. Chromeμ μ¬μ©ν΄ μ£ΌμΈμ.");
|
| 124 |
+
}
|
| 125 |
|
| 126 |
function stopRecording() {
|
| 127 |
+
if (recognition && isRecording) {
|
| 128 |
+
recognition.stop();
|
| 129 |
}
|
| 130 |
isRecording = false;
|
|
|
|
| 131 |
recordBtn.textContent = "π€ λ
Ήμ μμ";
|
| 132 |
recordBtn.classList.remove("recording");
|
| 133 |
}
|
| 134 |
|
| 135 |
+
recordBtn.addEventListener("click", () => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
if (!isRecording) {
|
| 137 |
+
if (recognition) recognition.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
} else {
|
| 139 |
stopRecording();
|
| 140 |
}
|