timefgf commited on
Commit
0d012d9
Β·
verified Β·
1 Parent(s): d496900

Update index.html

Browse files
Files changed (1) hide show
  1. 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
- const SPEECH_MODEL = "Xenova/whisper-base";[cite: 1]
47
- const SPEECH_LANGUAGE = "korean";[cite: 1]
48
- const TRANSLATE_MODEL = "Xenova/opus-mt-ko-en";[cite: 1]
 
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
- transcriber = await pipeline("automatic-speech-recognition", SPEECH_MODEL, { progress_callback: progressCallback });
72
- translator = await pipeline("translation", TRANSLATE_MODEL, { progress_callback: progressCallback });
 
 
 
73
 
74
  loadSeconds = ((performance.now() - loadStart) / 1000).toFixed(1);
75
- statusBox.textContent = `μ€€λΉ„ μ™„λ£Œ Β· (λͺ¨λΈ 뢈러였기 ${loadSeconds}초)`;
 
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();