Spaces:
Running
Running
Update index.html
Browse files- index.html +32 -23
index.html
CHANGED
|
@@ -3,23 +3,24 @@
|
|
| 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: #f1f3f4; border-radius: 6px; word-break: keep-all; line-height: 1.5; }
|
| 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; flex-wrap: wrap; }
|
| 16 |
-
#record-btn { padding: 8px 16px; font-size: 14px; cursor: pointer; border: 1px solid #dadce0; background: white; border-radius: 4px; }
|
| 17 |
-
#record-btn.recording { background-color: #fce8e6; color: #d93025; border-color: #d93025; font-weight: bold; }
|
|
|
|
| 18 |
.divider { color: #5f6368; font-size: 14px; }
|
| 19 |
</style>
|
| 20 |
</head>
|
| 21 |
<body>
|
| 22 |
-
<h1>μμ± λ²μκΈ°</h1>
|
| 23 |
<p class="sub">νκ΅μ΄λ‘ λ§νλ©΄ λ°μ μ κ³ , μμ΄λ‘ λ²μν΄ μ€ (μ΅λ 30μ΄)</p>
|
| 24 |
|
| 25 |
<div class="input-row">
|
|
@@ -32,20 +33,21 @@
|
|
| 32 |
|
| 33 |
<div class="box">
|
| 34 |
<h3>β μμλ€μ νκ΅μ΄</h3>
|
| 35 |
-
<textarea id="korean-text" readonly></textarea>
|
| 36 |
</div>
|
| 37 |
|
| 38 |
<div class="box">
|
| 39 |
<h3>β‘ μμ΄ λ²μ</h3>
|
| 40 |
-
<textarea id="english-text" readonly></textarea>
|
| 41 |
</div>
|
| 42 |
|
| 43 |
<script type="module">
|
| 44 |
import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.6";
|
| 45 |
|
| 46 |
-
|
| 47 |
-
const
|
| 48 |
-
const
|
|
|
|
| 49 |
const MAX_SECONDS = 30; // λ
Ήμ μ΅λ κΈΈμ΄(μ΄)[cite: 1]
|
| 50 |
|
| 51 |
const statusBox = document.getElementById("status");
|
|
@@ -58,23 +60,28 @@
|
|
| 58 |
let translator = null;
|
| 59 |
let loadSeconds = "";
|
| 60 |
|
| 61 |
-
// 1. λͺ¨λΈ λΆλ¬μ€κΈ°
|
| 62 |
async function loadModels() {
|
| 63 |
try {
|
| 64 |
const loadStart = performance.now();
|
| 65 |
const progressCallback = (data) => {
|
| 66 |
if (data.status === 'progress') {
|
| 67 |
-
statusBox.textContent = `λͺ¨λΈ λ€μ΄λ‘λ μ€... ${Math.round(data.progress)}%`;
|
| 68 |
}
|
| 69 |
};
|
| 70 |
|
| 71 |
-
|
| 72 |
-
translator = await
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
loadSeconds = ((performance.now() - loadStart) / 1000).toFixed(1);
|
| 75 |
-
statusBox.textContent = `μ€λΉ μλ£ Β· (
|
|
|
|
| 76 |
} catch (error) {
|
| 77 |
statusBox.textContent = `β λͺ¨λΈμ λΆλ¬μ€μ§ λͺ»ν¨ : ${error.message}`;
|
|
|
|
| 78 |
}
|
| 79 |
}
|
| 80 |
loadModels();
|
|
@@ -87,7 +94,8 @@
|
|
| 87 |
}
|
| 88 |
|
| 89 |
try {
|
| 90 |
-
statusBox.textContent = "μμ±μ ν
μ€νΈλ‘ λ³ννλ μ€...";
|
|
|
|
| 91 |
koreanBox.value = "";
|
| 92 |
englishBox.value = "";
|
| 93 |
|
|
@@ -102,7 +110,7 @@
|
|
| 102 |
const asrSeconds = ((performance.now() - asrStart) / 1000).toFixed(1);
|
| 103 |
koreanBox.value = koreanText;
|
| 104 |
|
| 105 |
-
statusBox.textContent = `λ°μ μ κΈ° ${asrSeconds}μ΄ Β· λ²μνλ μ€...`;
|
| 106 |
const transStart = performance.now();
|
| 107 |
|
| 108 |
const transResult = await translator(koreanText);
|
|
@@ -110,9 +118,11 @@
|
|
| 110 |
const transSeconds = ((performance.now() - transStart) / 1000).toFixed(1);
|
| 111 |
englishBox.value = englishText;
|
| 112 |
|
| 113 |
-
statusBox.textContent = `μλ£ Β· λ°μ μ κΈ° ${asrSeconds}μ΄ Β· λ²μ ${transSeconds}μ΄`;
|
|
|
|
| 114 |
} catch (error) {
|
| 115 |
statusBox.textContent = `β μ€ν μ€ μ€λ₯ λ°μ : ${error.message}`;
|
|
|
|
| 116 |
}
|
| 117 |
}
|
| 118 |
|
|
@@ -121,7 +131,7 @@
|
|
| 121 |
if (file) processAudioData(file);
|
| 122 |
});
|
| 123 |
|
| 124 |
-
// 3. λ§μ΄ν¬ λ
Ήμ μ μ΄ λ‘μ§
|
| 125 |
let mediaRecorder;
|
| 126 |
let audioChunks = [];
|
| 127 |
let isRecording = false;
|
|
@@ -138,9 +148,8 @@
|
|
| 138 |
}
|
| 139 |
|
| 140 |
recordBtn.addEventListener("click", async () => {
|
| 141 |
-
// λ§μ΄ν¬ μ§μ μ¬λΆ νμΈ
|
| 142 |
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
| 143 |
-
alert("νμ¬ λΈλΌμ°μ μμ λ§μ΄ν¬λ₯Ό μ§μνμ§ μκ±°λ κΆνμ΄ μ°¨λ¨λμ΄ μμ΅λλ€.");
|
| 144 |
return;
|
| 145 |
}
|
| 146 |
|
|
@@ -155,7 +164,6 @@
|
|
| 155 |
};
|
| 156 |
|
| 157 |
mediaRecorder.onstop = () => {
|
| 158 |
-
// νΈνμ±μ μν΄ ν¬λ§·μ κ°μ νμ§ μκ³ λΈλΌμ°μ κΈ°λ³Έκ°μ μ¬μ©
|
| 159 |
const audioBlob = new Blob(audioChunks);
|
| 160 |
processAudioData(audioBlob);
|
| 161 |
stream.getTracks().forEach(track => track.stop());
|
|
@@ -165,7 +173,8 @@
|
|
| 165 |
isRecording = true;
|
| 166 |
recordBtn.textContent = "βΉοΈ λ
Ήμ μ€μ§";
|
| 167 |
recordBtn.classList.add("recording");
|
| 168 |
-
statusBox.textContent = `λ
Ήμ μ€... (μ΅λ ${MAX_SECONDS}μ΄)`;[cite: 1]
|
|
|
|
| 169 |
|
| 170 |
recordingTimeout = setTimeout(() => {
|
| 171 |
if (isRecording) stopRecording();
|
|
|
|
| 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: #f1f3f4; border-radius: 6px; word-break: keep-all; line-height: 1.5; 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; flex-wrap: wrap; }
|
| 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>μμ± λ²μκΈ° β‘κ³ μ λͺ¨λ</h1>
|
| 24 |
<p class="sub">νκ΅μ΄λ‘ λ§νλ©΄ λ°μ μ κ³ , μμ΄λ‘ λ²μν΄ μ€ (μ΅λ 30μ΄)</p>
|
| 25 |
|
| 26 |
<div class="input-row">
|
|
|
|
| 33 |
|
| 34 |
<div class="box">
|
| 35 |
<h3>β μμλ€μ νκ΅μ΄</h3>
|
| 36 |
+
<textarea id="korean-text" readonly placeholder="μ¬κΈ°μ μΈμλ νκ΅μ΄κ° νμλ©λλ€."></textarea>
|
| 37 |
</div>
|
| 38 |
|
| 39 |
<div class="box">
|
| 40 |
<h3>β‘ μμ΄ λ²μ</h3>
|
| 41 |
+
<textarea id="english-text" readonly placeholder="μ¬κΈ°μ λ²μλ μμ΄κ° νμλ©λλ€."></textarea>
|
| 42 |
</div>
|
| 43 |
|
| 44 |
<script type="module">
|
| 45 |
import { pipeline } from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@3.7.6";
|
| 46 |
|
| 47 |
+
// λ‘λ© μλλ₯Ό 20μ΄ μ΄λ΄λ‘ μ€μ΄κΈ° μν΄ λͺ¨λΈμ tinyλ‘ λ³κ²½
|
| 48 |
+
const SPEECH_MODEL = "Xenova/whisper-tiny";
|
| 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");
|
|
|
|
| 60 |
let translator = null;
|
| 61 |
let loadSeconds = "";
|
| 62 |
|
| 63 |
+
// 1. λͺ¨λΈ λΆλ¬μ€κΈ°
|
| 64 |
async function loadModels() {
|
| 65 |
try {
|
| 66 |
const loadStart = performance.now();
|
| 67 |
const progressCallback = (data) => {
|
| 68 |
if (data.status === 'progress') {
|
| 69 |
+
statusBox.textContent = `π μ΄κ³ μ λͺ¨λΈ λ€μ΄λ‘λ μ€... ${Math.round(data.progress)}%`;
|
| 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 = `β
μ€λΉ μλ£ Β· (λ‘λ© μκ°: ${loadSeconds}μ΄)`;
|
| 81 |
+
statusBox.style.color = "#0f9d58";
|
| 82 |
} catch (error) {
|
| 83 |
statusBox.textContent = `β λͺ¨λΈμ λΆλ¬μ€μ§ λͺ»ν¨ : ${error.message}`;
|
| 84 |
+
statusBox.style.color = "#d93025";
|
| 85 |
}
|
| 86 |
}
|
| 87 |
loadModels();
|
|
|
|
| 94 |
}
|
| 95 |
|
| 96 |
try {
|
| 97 |
+
statusBox.textContent = "π μμ±μ ν
μ€νΈλ‘ λ³ννλ μ€...";
|
| 98 |
+
statusBox.style.color = "#1a73e8";
|
| 99 |
koreanBox.value = "";
|
| 100 |
englishBox.value = "";
|
| 101 |
|
|
|
|
| 110 |
const asrSeconds = ((performance.now() - asrStart) / 1000).toFixed(1);
|
| 111 |
koreanBox.value = koreanText;
|
| 112 |
|
| 113 |
+
statusBox.textContent = `π λ°μ μ κΈ° ${asrSeconds}μ΄ Β· λ²μνλ μ€...`;
|
| 114 |
const transStart = performance.now();
|
| 115 |
|
| 116 |
const transResult = await translator(koreanText);
|
|
|
|
| 118 |
const transSeconds = ((performance.now() - transStart) / 1000).toFixed(1);
|
| 119 |
englishBox.value = englishText;
|
| 120 |
|
| 121 |
+
statusBox.textContent = `β¨ μλ£ Β· λ°μ μ κΈ° ${asrSeconds}μ΄ Β· λ²μ ${transSeconds}μ΄`;
|
| 122 |
+
statusBox.style.color = "#0f9d58";
|
| 123 |
} catch (error) {
|
| 124 |
statusBox.textContent = `β μ€ν μ€ μ€λ₯ λ°μ : ${error.message}`;
|
| 125 |
+
statusBox.style.color = "#d93025";
|
| 126 |
}
|
| 127 |
}
|
| 128 |
|
|
|
|
| 131 |
if (file) processAudioData(file);
|
| 132 |
});
|
| 133 |
|
| 134 |
+
// 3. λ§μ΄ν¬ λ
Ήμ μ μ΄ λ‘μ§
|
| 135 |
let mediaRecorder;
|
| 136 |
let audioChunks = [];
|
| 137 |
let isRecording = false;
|
|
|
|
| 148 |
}
|
| 149 |
|
| 150 |
recordBtn.addEventListener("click", async () => {
|
|
|
|
| 151 |
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
| 152 |
+
alert("νμ¬ λΈλΌμ°μ μμ λ§μ΄ν¬λ₯Ό μ§μνμ§ μκ±°λ κΆνμ΄ μ°¨λ¨λμ΄ μμ΅λλ€.\nμ€μ μμ λ§μ΄ν¬ κΆνμ νμ©ν΄μ£ΌμΈμ.");
|
| 153 |
return;
|
| 154 |
}
|
| 155 |
|
|
|
|
| 164 |
};
|
| 165 |
|
| 166 |
mediaRecorder.onstop = () => {
|
|
|
|
| 167 |
const audioBlob = new Blob(audioChunks);
|
| 168 |
processAudioData(audioBlob);
|
| 169 |
stream.getTracks().forEach(track => track.stop());
|
|
|
|
| 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();
|