Miberd commited on
Commit
6e183e2
·
verified ·
1 Parent(s): 13c1a17

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +34 -27
index.html CHANGED
@@ -11,9 +11,7 @@
11
  p { font-size: 14px; color: #666; text-align: center; }
12
  .upload-area { border: 2px dashed #ccc; border-radius: 8px; padding: 20px; text-align: center; margin: 20px 0; background: #fafafa; }
13
 
14
- /* Скрываем стандартный инпут, но НЕ удаляем его из HTML */
15
  input[type="file"] { display: none; }
16
-
17
  .custom-file-upload { display: inline-block; padding: 10px 20px; background: #007bff; color: white; border-radius: 6px; cursor: pointer; font-weight: bold; margin-bottom: 10px; }
18
  .custom-file-upload:hover { background: #0056b3; }
19
 
@@ -25,7 +23,11 @@
25
 
26
  #analyzeBtn { display: block; width: 100%; padding: 12px; background: #28a745; color: white; border: none; border-radius: 6px; font-size: 16px; font-weight: bold; cursor: pointer; margin-top: 15px; }
27
  #analyzeBtn:disabled { background: #6c757d; cursor: not-allowed; }
28
- #status { margin-top: 15px; font-size: 14px; color: #ff9800; text-align: center; min-height: 20px; }
 
 
 
 
29
  #result { display: none; margin-top: 20px; padding: 15px; background: #e9ecef; border-radius: 8px; text-align: center; }
30
  #downloadLink { display: inline-block; padding: 10px 20px; background: #17a2b8; color: white; text-decoration: none; border-radius: 6px; font-weight: bold; }
31
  </style>
@@ -37,7 +39,6 @@
37
 
38
  <div class="upload-area">
39
  <label for="audioFile" class="custom-file-upload">Выбрать файл</label>
40
- <!-- ВОТ ОН, Я ЕГО ВЕРНУЛ! -->
41
  <input type="file" id="audioFile" accept="audio/*">
42
  <button type="button" id="recordBtn">🎤 Записать с микрофона</button>
43
 
@@ -79,6 +80,7 @@
79
  recordStatus.textContent = '';
80
  resultDiv.style.display = 'none';
81
  statusDiv.textContent = '';
 
82
  }
83
  });
84
 
@@ -121,6 +123,7 @@
121
  recordBtn.style.background = "#6c757d";
122
  resultDiv.style.display = 'none';
123
  statusDiv.textContent = 'Нажмите "Анализировать аудио".';
 
124
 
125
  stream.getTracks().forEach(track => track.stop());
126
  };
@@ -132,34 +135,33 @@
132
  recordStatus.style.color = "#28a745";
133
  fileNameDisplay.textContent = "";
134
  statusDiv.textContent = "";
 
135
 
136
  } catch (err) {
137
  console.error("Ошибка доступа к микрофону:", err);
138
- if (err.name === 'NotAllowedError' || err.name === 'PermissionDeniedError') {
139
- recordStatus.textContent = "Микрофон заблокирован. Разрешите доступ в настройках браузера.";
140
- } else if (err.name === 'NotFoundError') {
141
- recordStatus.textContent = "Микрофон не найден. Проверьте, подключен ли он.";
142
- } else {
143
- recordStatus.textContent = "Ошибка: " + err.message;
144
- }
145
  recordStatus.style.color = "#dc3545";
146
  }
147
  });
148
 
149
  async function decodeAndResample(file) {
150
- const arrayBuffer = await file.arrayBuffer();
151
- const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
152
- const decoded = await audioCtx.decodeAudioData(arrayBuffer);
153
- await audioCtx.close();
154
-
155
- const sampleRate = 22050;
156
- const offlineCtx = new OfflineAudioContext(1, Math.max(1, Math.ceil(decoded.duration * sampleRate)), sampleRate);
157
- const source = offlineCtx.createBufferSource();
158
- source.buffer = decoded;
159
- source.connect(offlineCtx.destination);
160
- source.start();
161
- const rendered = await offlineCtx.startRendering();
162
- return Float32Array.from(rendered.getChannelData(0));
 
 
 
 
163
  }
164
 
165
  analyzeBtn.addEventListener('click', async () => {
@@ -170,10 +172,12 @@
170
 
171
  analyzeBtn.disabled = true;
172
  resultDiv.style.display = 'none';
 
173
  statusDiv.textContent = 'Шаг 1/3: Загрузка модели...';
174
 
175
  try {
176
- const modelURL = 'https://huggingface.co/spotify/basic-pitch/resolve/main/model.json';
 
177
  const basicPitch = new BasicPitch(modelURL);
178
 
179
  statusDiv.textContent = 'Шаг 2/3: Обработка аудио...';
@@ -219,10 +223,13 @@
219
  downloadLink.download = `notes_${new Date().getTime()}.mid`;
220
  resultDiv.style.display = 'block';
221
  statusDiv.textContent = 'Готово!';
 
222
 
223
  } catch (error) {
224
- console.error(error);
225
- statusDiv.textContent = 'Ошибка при обработке. Возможно, формат аудио не поддерживается.';
 
 
226
  } finally {
227
  analyzeBtn.disabled = false;
228
  }
 
11
  p { font-size: 14px; color: #666; text-align: center; }
12
  .upload-area { border: 2px dashed #ccc; border-radius: 8px; padding: 20px; text-align: center; margin: 20px 0; background: #fafafa; }
13
 
 
14
  input[type="file"] { display: none; }
 
15
  .custom-file-upload { display: inline-block; padding: 10px 20px; background: #007bff; color: white; border-radius: 6px; cursor: pointer; font-weight: bold; margin-bottom: 10px; }
16
  .custom-file-upload:hover { background: #0056b3; }
17
 
 
23
 
24
  #analyzeBtn { display: block; width: 100%; padding: 12px; background: #28a745; color: white; border: none; border-radius: 6px; font-size: 16px; font-weight: bold; cursor: pointer; margin-top: 15px; }
25
  #analyzeBtn:disabled { background: #6c757d; cursor: not-allowed; }
26
+
27
+ /* Стили для вывода ошибок */
28
+ #status { margin-top: 15px; font-size: 14px; color: #ff9800; text-align: center; min-height: 20px; word-wrap: break-word; }
29
+ .error-text { color: #dc3545 !important; font-weight: bold; font-size: 13px; background: #f8d7da; padding: 10px; border-radius: 5px; }
30
+
31
  #result { display: none; margin-top: 20px; padding: 15px; background: #e9ecef; border-radius: 8px; text-align: center; }
32
  #downloadLink { display: inline-block; padding: 10px 20px; background: #17a2b8; color: white; text-decoration: none; border-radius: 6px; font-weight: bold; }
33
  </style>
 
39
 
40
  <div class="upload-area">
41
  <label for="audioFile" class="custom-file-upload">Выбрать файл</label>
 
42
  <input type="file" id="audioFile" accept="audio/*">
43
  <button type="button" id="recordBtn">🎤 Записать с микрофона</button>
44
 
 
80
  recordStatus.textContent = '';
81
  resultDiv.style.display = 'none';
82
  statusDiv.textContent = '';
83
+ statusDiv.className = '';
84
  }
85
  });
86
 
 
123
  recordBtn.style.background = "#6c757d";
124
  resultDiv.style.display = 'none';
125
  statusDiv.textContent = 'Нажмите "Анализировать аудио".';
126
+ statusDiv.className = '';
127
 
128
  stream.getTracks().forEach(track => track.stop());
129
  };
 
135
  recordStatus.style.color = "#28a745";
136
  fileNameDisplay.textContent = "";
137
  statusDiv.textContent = "";
138
+ statusDiv.className = '';
139
 
140
  } catch (err) {
141
  console.error("Ошибка доступа к микрофону:", err);
142
+ recordStatus.textContent = "Ошибка микрофона: " + err.message;
 
 
 
 
 
 
143
  recordStatus.style.color = "#dc3545";
144
  }
145
  });
146
 
147
  async function decodeAndResample(file) {
148
+ try {
149
+ const arrayBuffer = await file.arrayBuffer();
150
+ const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
151
+ const decoded = await audioCtx.decodeAudioData(arrayBuffer);
152
+ await audioCtx.close();
153
+
154
+ const sampleRate = 22050;
155
+ const offlineCtx = new OfflineAudioContext(1, Math.max(1, Math.ceil(decoded.duration * sampleRate)), sampleRate);
156
+ const source = offlineCtx.createBufferSource();
157
+ source.buffer = decoded;
158
+ source.connect(offlineCtx.destination);
159
+ source.start();
160
+ const rendered = await offlineCtx.startRendering();
161
+ return Float32Array.from(rendered.getChannelData(0));
162
+ } catch (e) {
163
+ throw new Error("Ошибка чтения аудио. Возможно, формат файла не поддерживается браузером. (" + e.message + ")");
164
+ }
165
  }
166
 
167
  analyzeBtn.addEventListener('click', async () => {
 
172
 
173
  analyzeBtn.disabled = true;
174
  resultDiv.style.display = 'none';
175
+ statusDiv.className = '';
176
  statusDiv.textContent = 'Шаг 1/3: Загрузка модели...';
177
 
178
  try {
179
+ // Используем официальную модель с надежного CDN
180
+ const modelURL = 'https://cdn.jsdelivr.net/npm/@spotify/basic-pitch@1.0.1/model/model.json';
181
  const basicPitch = new BasicPitch(modelURL);
182
 
183
  statusDiv.textContent = 'Шаг 2/3: Обработка аудио...';
 
223
  downloadLink.download = `notes_${new Date().getTime()}.mid`;
224
  resultDiv.style.display = 'block';
225
  statusDiv.textContent = 'Готово!';
226
+ statusDiv.className = '';
227
 
228
  } catch (error) {
229
+ console.error("Детали ошибки:", error);
230
+ // Теперь мы выводим точный текст ошибки на экран
231
+ statusDiv.className = 'error-text';
232
+ statusDiv.textContent = error.message;
233
  } finally {
234
  analyzeBtn.disabled = false;
235
  }