Spaces:
Sleeping
Sleeping
Update static/script.js
Browse files- static/script.js +4 -44
static/script.js
CHANGED
|
@@ -9,13 +9,12 @@ window.onload = function () {
|
|
| 9 |
const recognition = new SpeechRecognition();
|
| 10 |
recognition.continuous = true;
|
| 11 |
recognition.lang = "en-US";
|
| 12 |
-
let listeningForCommands = false;
|
| 13 |
|
| 14 |
function startListening() {
|
| 15 |
recognition.start();
|
| 16 |
let statusElement = document.getElementById("status");
|
| 17 |
if (statusElement) {
|
| 18 |
-
statusElement.innerText = "Listening...";
|
| 19 |
}
|
| 20 |
}
|
| 21 |
|
|
@@ -23,19 +22,9 @@ window.onload = function () {
|
|
| 23 |
let transcript = event.results[event.results.length - 1][0].transcript.toLowerCase();
|
| 24 |
console.log("You said:", transcript);
|
| 25 |
|
| 26 |
-
if (
|
| 27 |
-
console.log("Wake word detected!
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
let statusElement = document.getElementById("status");
|
| 31 |
-
if (statusElement) {
|
| 32 |
-
statusElement.innerText = "Listening for command...";
|
| 33 |
-
}
|
| 34 |
-
|
| 35 |
-
speak("Hello! What can I do for you?");
|
| 36 |
-
} else if (listeningForCommands) {
|
| 37 |
-
console.log("Command received:", transcript);
|
| 38 |
-
sendCommandToServer(transcript);
|
| 39 |
}
|
| 40 |
};
|
| 41 |
|
|
@@ -43,35 +32,6 @@ window.onload = function () {
|
|
| 43 |
console.error("Speech recognition error:", event.error);
|
| 44 |
};
|
| 45 |
|
| 46 |
-
function sendCommandToServer(command) {
|
| 47 |
-
fetch("/process_command", {
|
| 48 |
-
method: "POST",
|
| 49 |
-
headers: {
|
| 50 |
-
"Content-Type": "application/json",
|
| 51 |
-
},
|
| 52 |
-
body: JSON.stringify({ command: command }),
|
| 53 |
-
})
|
| 54 |
-
.then(response => response.json())
|
| 55 |
-
.then(data => {
|
| 56 |
-
console.log("Server response:", data.response);
|
| 57 |
-
speak(data.response);
|
| 58 |
-
listeningForCommands = false;
|
| 59 |
-
|
| 60 |
-
let statusElement = document.getElementById("status");
|
| 61 |
-
if (statusElement) {
|
| 62 |
-
statusElement.innerText = "Listening for wake word...";
|
| 63 |
-
}
|
| 64 |
-
})
|
| 65 |
-
.catch(error => console.error("Error sending command:", error));
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
function speak(text) {
|
| 69 |
-
let speech = new SpeechSynthesisUtterance(text);
|
| 70 |
-
speech.lang = "en-US";
|
| 71 |
-
speech.rate = 1;
|
| 72 |
-
window.speechSynthesis.speak(speech);
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
startListening();
|
| 76 |
};
|
| 77 |
|
|
|
|
| 9 |
const recognition = new SpeechRecognition();
|
| 10 |
recognition.continuous = true;
|
| 11 |
recognition.lang = "en-US";
|
|
|
|
| 12 |
|
| 13 |
function startListening() {
|
| 14 |
recognition.start();
|
| 15 |
let statusElement = document.getElementById("status");
|
| 16 |
if (statusElement) {
|
| 17 |
+
statusElement.innerText = "Listening for 'Hi Biriyani Hub'...";
|
| 18 |
}
|
| 19 |
}
|
| 20 |
|
|
|
|
| 22 |
let transcript = event.results[event.results.length - 1][0].transcript.toLowerCase();
|
| 23 |
console.log("You said:", transcript);
|
| 24 |
|
| 25 |
+
if (transcript.includes("hi biriyani hub")) {
|
| 26 |
+
console.log("Wake word detected! Redirecting to landing page...");
|
| 27 |
+
window.location.href = "/landing"; // Redirects to landing page
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
}
|
| 29 |
};
|
| 30 |
|
|
|
|
| 32 |
console.error("Speech recognition error:", event.error);
|
| 33 |
};
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
startListening();
|
| 36 |
};
|
| 37 |
|