Spaces:
Sleeping
Sleeping
Update static/js/script.js
Browse files- static/js/script.js +11 -4
static/js/script.js
CHANGED
|
@@ -2,6 +2,7 @@ let isRecording = false;
|
|
| 2 |
let mediaRecorder;
|
| 3 |
let recordedChunks = [];
|
| 4 |
|
|
|
|
| 5 |
document.getElementById('recordButton').addEventListener('click', async function () {
|
| 6 |
if (!isRecording) {
|
| 7 |
startRecording();
|
|
@@ -20,12 +21,15 @@ function startRecording() {
|
|
| 20 |
recordedChunks.push(e.data);
|
| 21 |
};
|
| 22 |
|
|
|
|
| 23 |
document.getElementById('recordButton').textContent = 'Stop';
|
|
|
|
| 24 |
document.getElementById('recordStatus').textContent = 'Recording...';
|
|
|
|
| 25 |
isRecording = true;
|
| 26 |
})
|
| 27 |
.catch(function (err) {
|
| 28 |
-
console.
|
| 29 |
});
|
| 30 |
}
|
| 31 |
|
|
@@ -34,13 +38,16 @@ function stopRecording() {
|
|
| 34 |
|
| 35 |
mediaRecorder.onstop = function () {
|
| 36 |
const blob = new Blob(recordedChunks, { type: 'audio/webm' });
|
| 37 |
-
const audioURL = window.URL.createObjectURL(blob);
|
| 38 |
recordedChunks = [];
|
|
|
|
| 39 |
|
|
|
|
| 40 |
document.getElementById('recordButton').textContent = 'Start';
|
|
|
|
| 41 |
document.getElementById('recordStatus').textContent = 'Tap to Record';
|
| 42 |
-
document.getElementById('transcribeContainer').style.display = 'block';
|
| 43 |
|
|
|
|
| 44 |
document.getElementById('transcribeButton').addEventListener('click', function () {
|
| 45 |
transcribeAudio(blob);
|
| 46 |
});
|
|
@@ -53,7 +60,7 @@ function transcribeAudio(blob) {
|
|
| 53 |
const formData = new FormData();
|
| 54 |
formData.append('audio', blob, 'audio.webm');
|
| 55 |
|
| 56 |
-
fetch('/transcribe', {
|
| 57 |
method: 'POST',
|
| 58 |
body: formData
|
| 59 |
})
|
|
|
|
| 2 |
let mediaRecorder;
|
| 3 |
let recordedChunks = [];
|
| 4 |
|
| 5 |
+
// Handles the recording button click event
|
| 6 |
document.getElementById('recordButton').addEventListener('click', async function () {
|
| 7 |
if (!isRecording) {
|
| 8 |
startRecording();
|
|
|
|
| 21 |
recordedChunks.push(e.data);
|
| 22 |
};
|
| 23 |
|
| 24 |
+
// Update button text and style
|
| 25 |
document.getElementById('recordButton').textContent = 'Stop';
|
| 26 |
+
document.getElementById('recordButton').classList.add('recording');
|
| 27 |
document.getElementById('recordStatus').textContent = 'Recording...';
|
| 28 |
+
document.getElementById('transcribeContainer').style.display = 'none'; // Hide Transcribe button initially
|
| 29 |
isRecording = true;
|
| 30 |
})
|
| 31 |
.catch(function (err) {
|
| 32 |
+
console.error('The following error occurred: ' + err);
|
| 33 |
});
|
| 34 |
}
|
| 35 |
|
|
|
|
| 38 |
|
| 39 |
mediaRecorder.onstop = function () {
|
| 40 |
const blob = new Blob(recordedChunks, { type: 'audio/webm' });
|
|
|
|
| 41 |
recordedChunks = [];
|
| 42 |
+
const audioURL = window.URL.createObjectURL(blob);
|
| 43 |
|
| 44 |
+
// Update button text and style
|
| 45 |
document.getElementById('recordButton').textContent = 'Start';
|
| 46 |
+
document.getElementById('recordButton').classList.remove('recording');
|
| 47 |
document.getElementById('recordStatus').textContent = 'Tap to Record';
|
| 48 |
+
document.getElementById('transcribeContainer').style.display = 'block'; // Show Transcribe button
|
| 49 |
|
| 50 |
+
// Set up the Transcribe button click event
|
| 51 |
document.getElementById('transcribeButton').addEventListener('click', function () {
|
| 52 |
transcribeAudio(blob);
|
| 53 |
});
|
|
|
|
| 60 |
const formData = new FormData();
|
| 61 |
formData.append('audio', blob, 'audio.webm');
|
| 62 |
|
| 63 |
+
fetch('https://tri4-semalab.hf.space/transcribe', { // External URL
|
| 64 |
method: 'POST',
|
| 65 |
body: formData
|
| 66 |
})
|