lokesh341 commited on
Commit
9a74cb9
·
verified ·
1 Parent(s): 0e4d29e

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +32 -25
templates/index.html CHANGED
@@ -101,33 +101,40 @@
101
  </div>
102
 
103
  <script>
104
- // This function simulates the speech recognition and fills in the fields after listening
105
- async function startListening() {
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- // Simulate listening for name
113
- setTimeout(() => {
114
- nameInput.value = "John Doe"; // Simulated name input from voice
115
- status.textContent = 'Listening for your email...';
116
- }, 5000);
117
-
118
- // Simulate listening for email after 5 seconds
119
- setTimeout(() => {
120
- emailInput.value = "[email protected]"; // Simulated email input from voice
121
- status.textContent = 'Registration complete.';
122
-
123
- // Auto refresh after 15 seconds
124
- setTimeout(() => {
125
- location.reload();
126
- }, 15000); // 15 seconds auto-refresh
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
+