dschandra commited on
Commit
af79f32
·
verified ·
1 Parent(s): d5b9194

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -92,11 +92,11 @@ html_code = """
92
  const response = document.getElementById('response');
93
  let mediaRecorder;
94
  let audioChunks = [];
95
- let isConversationActive = false;
96
 
97
  micButton.addEventListener('click', () => {
98
- if (!isConversationActive) {
99
- isConversationActive = true;
100
  startConversation();
101
  }
102
  });
@@ -151,7 +151,7 @@ html_code = """
151
 
152
  if (data.response.includes("Goodbye")) {
153
  status.textContent = 'Conversation ended. Press the mic button to start again.';
154
- isConversationActive = false;
155
  } else {
156
  status.textContent = 'Listening...';
157
  setTimeout(startListening, 1000);
@@ -160,13 +160,13 @@ html_code = """
160
  response.textContent = 'Error occurred. Please try again.';
161
  response.style.display = 'block';
162
  status.textContent = 'Press the mic button to restart the conversation.';
163
- isConversationActive = false;
164
  }
165
  };
166
  setTimeout(() => mediaRecorder.stop(), 10000); // Wait for 10 seconds of speaking time
167
  }).catch(() => {
168
  status.textContent = 'Microphone access denied.';
169
- isConversationActive = false;
170
  });
171
  }
172
  </script>
 
92
  const response = document.getElementById('response');
93
  let mediaRecorder;
94
  let audioChunks = [];
95
+ let isListening = false;
96
 
97
  micButton.addEventListener('click', () => {
98
+ if (!isListening) {
99
+ isListening = true;
100
  startConversation();
101
  }
102
  });
 
151
 
152
  if (data.response.includes("Goodbye")) {
153
  status.textContent = 'Conversation ended. Press the mic button to start again.';
154
+ isListening = false;
155
  } else {
156
  status.textContent = 'Listening...';
157
  setTimeout(startListening, 1000);
 
160
  response.textContent = 'Error occurred. Please try again.';
161
  response.style.display = 'block';
162
  status.textContent = 'Press the mic button to restart the conversation.';
163
+ isListening = false;
164
  }
165
  };
166
  setTimeout(() => mediaRecorder.stop(), 10000); // Wait for 10 seconds of speaking time
167
  }).catch(() => {
168
  status.textContent = 'Microphone access denied.';
169
+ isListening = false;
170
  });
171
  }
172
  </script>