Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +32 -25
templates/index.html
CHANGED
@@ -101,33 +101,40 @@
|
|
101 |
</div>
|
102 |
|
103 |
<script>
|
104 |
-
|
105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
const status = document.getElementById('status');
|
107 |
const nameInput = document.getElementById('name');
|
108 |
const emailInput = document.getElementById('email');
|
109 |
|
|
|
110 |
status.textContent = 'Playing welcome message...';
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
}, 10000);
|
128 |
-
}
|
129 |
-
|
130 |
-
document.getElementById('startListeningBtn').addEventListener('click', startListening);
|
131 |
-
</script>
|
132 |
-
</body>
|
133 |
-
</html>
|
|
|
101 |
</div>
|
102 |
|
103 |
<script>
|
104 |
+
let recognition;
|
105 |
+
let isListening = false;
|
106 |
+
|
107 |
+
// Initialize speech recognition
|
108 |
+
if ('webkitSpeechRecognition' in window) {
|
109 |
+
recognition = new webkitSpeechRecognition();
|
110 |
+
recognition.continuous = true;
|
111 |
+
recognition.interimResults = true;
|
112 |
+
recognition.lang = 'en-US';
|
113 |
+
} else {
|
114 |
+
alert("Speech Recognition API is not supported in this browser.");
|
115 |
+
}
|
116 |
+
|
117 |
+
// Function to start listening to voice input
|
118 |
+
function startListening() {
|
119 |
const status = document.getElementById('status');
|
120 |
const nameInput = document.getElementById('name');
|
121 |
const emailInput = document.getElementById('email');
|
122 |
|
123 |
+
// Welcome Message (Play Audio)
|
124 |
status.textContent = 'Playing welcome message...';
|
125 |
+
const welcomeMessage = new SpeechSynthesisUtterance("Welcome to Biryani Hub. Please say your name after the beep.");
|
126 |
+
window.speechSynthesis.speak(welcomeMessage);
|
127 |
+
|
128 |
+
// Wait until speech synthesis is done and then start listening
|
129 |
+
welcomeMessage.onend = () => {
|
130 |
+
status.textContent = 'Listening for your name...';
|
131 |
+
recognition.start(); // Start voice recognition
|
132 |
+
};
|
133 |
+
|
134 |
+
// Handle recognition results
|
135 |
+
recognition.onresult = function(event) {
|
136 |
+
const transcript = event.results[event.resultIndex][0].transcript.trim();
|
137 |
+
if (event.results[event.resultIndex].isFinal) {
|
138 |
+
if (!nameInput.value) {
|
139 |
+
// If name is empty, fill it with the recognized text
|
140 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|