lokesh341 commited on
Commit
39f158e
·
verified ·
1 Parent(s): 8d52aa5

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +8 -52
templates/index.html CHANGED
@@ -85,9 +85,6 @@
85
  <!-- Info Message for Listening -->
86
  <p class="info">Listening will start automatically...</p>
87
 
88
- <!-- Welcome Button -->
89
- <button class="btn" id="startListeningBtn">Welcome to Biryani Hub</button>
90
-
91
  <!-- Status Message -->
92
  <p class="status" id="status">Initializing...</p>
93
  </div>
@@ -95,8 +92,6 @@
95
  <script>
96
  let recognition;
97
  let isListening = false;
98
- let isNameCaptured = false;
99
-
100
  // Initialize speech recognition
101
  if ('webkitSpeechRecognition' in window) {
102
  recognition = new webkitSpeechRecognition();
@@ -107,52 +102,13 @@
107
  alert("Speech Recognition API is not supported in this browser.");
108
  }
109
 
110
- // Function to start listening to voice input
111
- function startListening() {
112
- const status = document.getElementById('status');
113
- const nameInput = document.getElementById('name');
114
- const emailInput = document.getElementById('email');
115
-
116
- // Welcome Message (Play Audio)
117
- status.textContent = 'Playing welcome message...';
118
- const welcomeMessage = new SpeechSynthesisUtterance("Welcome to Biryani Hub. Please say your name after the beep.");
119
- window.speechSynthesis.speak(welcomeMessage);
120
-
121
- // Wait until speech synthesis is done and then start listening
122
- welcomeMessage.onend = () => {
123
- status.textContent = 'Listening for your name...';
124
- recognition.start(); // Start voice recognition
125
- };
126
-
127
- // Handle recognition results
128
- recognition.onresult = function(event) {
129
- const transcript = event.results[event.resultIndex][0].transcript.trim();
130
- if (event.results[event.resultIndex].isFinal) {
131
- if (!isNameCaptured) {
132
- // If name is empty, fill it with the recognized text
133
- nameInput.value = transcript;
134
- status.textContent = 'Listening for your email...';
135
- isNameCaptured = true; // Mark name as captured
136
- recognition.stop(); // Stop listening for name
137
- recognition.start(); // Start listening for email
138
- } else if (isNameCaptured && !emailInput.value) {
139
- // If email is empty, fill it with the recognized text
140
- emailInput.value = transcript;
141
- status.textContent = 'Registration complete.';
142
-
143
- // After registration is complete, refresh page automatically after 15 seconds
144
- setTimeout(() => location.reload(), 15000); // Refresh after 15 seconds
145
- }
146
- }
147
- };
148
-
149
- recognition.onerror = function(event) {
150
- console.error('Speech recognition error:', event.error);
151
- status.textContent = 'Error recognizing speech. Please try again.';
152
- };
153
  }
154
 
155
- document.getElementById('startListeningBtn').addEventListener('click', startListening);
156
- </script>
157
- </body>
158
- </html>
 
85
  <!-- Info Message for Listening -->
86
  <p class="info">Listening will start automatically...</p>
87
 
 
 
 
88
  <!-- Status Message -->
89
  <p class="status" id="status">Initializing...</p>
90
  </div>
 
92
  <script>
93
  let recognition;
94
  let isListening = false;
 
 
95
  // Initialize speech recognition
96
  if ('webkitSpeechRecognition' in window) {
97
  recognition = new webkitSpeechRecognition();
 
102
  alert("Speech Recognition API is not supported in this browser.");
103
  }
104
 
105
+ // Function to make the welcome message speak automatically when the page loads
106
+ function welcomeMessage() {
107
+ const welcomeMsg = "Welcome to Biryani Hub. Please say your name after the beep.";
108
+ const speech = new SpeechSynthesisUtterance(welcomeMsg);
109
+ window.speechSynthesis.speak(speech);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
  }
111
 
112
+ // Make sure to start listening as soon as the page loads
113
+ window.onload = function () {
114
+ welcomeMessage(); // Automatically say the welcome mes