Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +18 -2
index.html
CHANGED
@@ -19,8 +19,10 @@
|
|
19 |
<div class="card-body text-center">
|
20 |
<button type="button" class="btn btn-danger" id="recordButton"><i class="fas fa-record-vinyl"></i> Start Recording</button>
|
21 |
<button type="button" class="btn btn-secondary" id="stopButton" disabled><i class="fas fa-stop"></i> Stop Recording</button>
|
|
|
22 |
<p class="mt-3">Your recording will appear below:</p>
|
23 |
<audio id="audioPlayback" controls class="d-none mt-2"></audio>
|
|
|
24 |
</div>
|
25 |
</div>
|
26 |
|
@@ -152,11 +154,14 @@
|
|
152 |
<script>
|
153 |
let recordButton = document.getElementById('recordButton');
|
154 |
let stopButton = document.getElementById('stopButton');
|
|
|
155 |
let audioPlayback = document.getElementById('audioPlayback');
|
156 |
let generatedText = document.getElementById('generatedText');
|
|
|
157 |
|
158 |
let mediaRecorder;
|
159 |
let audioChunks = [];
|
|
|
160 |
|
161 |
recordButton.addEventListener('click', () => {
|
162 |
navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
|
@@ -169,13 +174,15 @@
|
|
169 |
});
|
170 |
|
171 |
mediaRecorder.addEventListener('stop', async () => {
|
172 |
-
|
|
|
173 |
const audioUrl = URL.createObjectURL(audioBlob);
|
174 |
audioPlayback.src = audioUrl;
|
175 |
audioPlayback.classList.remove('d-none');
|
176 |
|
177 |
const transcription = await transcribeAudio(audioBlob);
|
178 |
generatedText.value = transcription || "Transcription failed.";
|
|
|
179 |
});
|
180 |
|
181 |
recordButton.disabled = true;
|
@@ -189,6 +196,15 @@
|
|
189 |
stopButton.disabled = true;
|
190 |
});
|
191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
async function transcribeAudio(audioFile) {
|
193 |
const formData = new FormData();
|
194 |
formData.append('file', audioFile,'recording.webm');
|
@@ -263,4 +279,4 @@ var jsonObject = JSON.parse(jsonPart[0]);
|
|
263 |
};
|
264 |
</script>
|
265 |
</body>
|
266 |
-
</html>
|
|
|
19 |
<div class="card-body text-center">
|
20 |
<button type="button" class="btn btn-danger" id="recordButton"><i class="fas fa-record-vinyl"></i> Start Recording</button>
|
21 |
<button type="button" class="btn btn-secondary" id="stopButton" disabled><i class="fas fa-stop"></i> Stop Recording</button>
|
22 |
+
<button type="button" class="btn btn-warning" id="refreshButton"><i class="fas fa-sync-alt"></i> Refresh</button>
|
23 |
<p class="mt-3">Your recording will appear below:</p>
|
24 |
<audio id="audioPlayback" controls class="d-none mt-2"></audio>
|
25 |
+
<div id="loadingIcon" class="d-none mt-2"><i class="fas fa-spinner fa-spin"></i> Loading...</div>
|
26 |
</div>
|
27 |
</div>
|
28 |
|
|
|
154 |
<script>
|
155 |
let recordButton = document.getElementById('recordButton');
|
156 |
let stopButton = document.getElementById('stopButton');
|
157 |
+
let refreshButton = document.getElementById('refreshButton');
|
158 |
let audioPlayback = document.getElementById('audioPlayback');
|
159 |
let generatedText = document.getElementById('generatedText');
|
160 |
+
let loadingIcon = document.getElementById('loadingIcon');
|
161 |
|
162 |
let mediaRecorder;
|
163 |
let audioChunks = [];
|
164 |
+
let audioBlob;
|
165 |
|
166 |
recordButton.addEventListener('click', () => {
|
167 |
navigator.mediaDevices.getUserMedia({ audio: true }).then(stream => {
|
|
|
174 |
});
|
175 |
|
176 |
mediaRecorder.addEventListener('stop', async () => {
|
177 |
+
loadingIcon.classList.remove('d-none');
|
178 |
+
audioBlob = new Blob(audioChunks, { type: 'audio/webm' });
|
179 |
const audioUrl = URL.createObjectURL(audioBlob);
|
180 |
audioPlayback.src = audioUrl;
|
181 |
audioPlayback.classList.remove('d-none');
|
182 |
|
183 |
const transcription = await transcribeAudio(audioBlob);
|
184 |
generatedText.value = transcription || "Transcription failed.";
|
185 |
+
loadingIcon.classList.add('d-none');
|
186 |
});
|
187 |
|
188 |
recordButton.disabled = true;
|
|
|
196 |
stopButton.disabled = true;
|
197 |
});
|
198 |
|
199 |
+
refreshButton.addEventListener('click', async () => {
|
200 |
+
if (audioBlob) {
|
201 |
+
loadingIcon.classList.remove('d-none');
|
202 |
+
const transcription = await transcribeAudio(audioBlob);
|
203 |
+
generatedText.value = transcription || "Transcription failed.";
|
204 |
+
loadingIcon.classList.add('d-none');
|
205 |
+
}
|
206 |
+
});
|
207 |
+
|
208 |
async function transcribeAudio(audioFile) {
|
209 |
const formData = new FormData();
|
210 |
formData.append('file', audioFile,'recording.webm');
|
|
|
279 |
};
|
280 |
</script>
|
281 |
</body>
|
282 |
+
</html>
|