Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +18 -33
templates/index.html
CHANGED
|
@@ -30,37 +30,24 @@
|
|
| 30 |
});
|
| 31 |
}
|
| 32 |
|
| 33 |
-
async function requestMicrophonePermission() {
|
| 34 |
-
try {
|
| 35 |
-
await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 36 |
-
console.log("Microphone access granted.");
|
| 37 |
-
} catch (err) {
|
| 38 |
-
alert("Microphone access denied. Please enable microphone permissions in your browser.");
|
| 39 |
-
}
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
async function recordAudio() {
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
});
|
| 61 |
-
} catch (err) {
|
| 62 |
-
alert("Error accessing the microphone. Please check your browser settings.");
|
| 63 |
-
}
|
| 64 |
}
|
| 65 |
|
| 66 |
async function transcribeAudio(audioBlob) {
|
|
@@ -73,12 +60,10 @@
|
|
| 73 |
});
|
| 74 |
|
| 75 |
const result = await response.json();
|
| 76 |
-
return result.text ||
|
| 77 |
}
|
| 78 |
|
| 79 |
async function startInteraction() {
|
| 80 |
-
await requestMicrophonePermission();
|
| 81 |
-
|
| 82 |
const status = document.getElementById('status');
|
| 83 |
const nameInput = document.getElementById('name');
|
| 84 |
const emailInput = document.getElementById('email');
|
|
|
|
| 30 |
});
|
| 31 |
}
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
async function recordAudio() {
|
| 34 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 35 |
+
const mediaRecorder = new MediaRecorder(stream, { mimeType: 'audio/webm' });
|
| 36 |
+
let audioChunks = [];
|
| 37 |
+
|
| 38 |
+
return new Promise(resolve => {
|
| 39 |
+
mediaRecorder.ondataavailable = event => {
|
| 40 |
+
audioChunks.push(event.data);
|
| 41 |
+
};
|
| 42 |
+
|
| 43 |
+
mediaRecorder.onstop = () => {
|
| 44 |
+
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
| 45 |
+
resolve(audioBlob);
|
| 46 |
+
};
|
| 47 |
+
|
| 48 |
+
mediaRecorder.start();
|
| 49 |
+
setTimeout(() => mediaRecorder.stop(), 5000); // ✅ Record for 5 seconds
|
| 50 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
async function transcribeAudio(audioBlob) {
|
|
|
|
| 60 |
});
|
| 61 |
|
| 62 |
const result = await response.json();
|
| 63 |
+
return result.text || 'Error capturing speech';
|
| 64 |
}
|
| 65 |
|
| 66 |
async function startInteraction() {
|
|
|
|
|
|
|
| 67 |
const status = document.getElementById('status');
|
| 68 |
const nameInput = document.getElementById('name');
|
| 69 |
const emailInput = document.getElementById('email');
|