geethareddy commited on
Commit
b65533c
·
verified ·
1 Parent(s): 40f37e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -61,22 +61,18 @@ html_code = """
61
  const micButton = document.getElementById('mic-button');
62
  const status = document.getElementById('status');
63
  const response = document.getElementById('response');
64
- let isConversationActive = false;
65
 
66
  micButton.addEventListener('click', () => {
67
- if (!isConversationActive) {
68
- isConversationActive = true;
69
  startConversation();
70
  }
71
  });
72
 
73
  function startConversation() {
74
- const utterance = new SpeechSynthesisUtterance('Please give your order.');
75
- speechSynthesis.speak(utterance);
76
- utterance.onend = () => {
77
- status.textContent = 'Listening...';
78
- startListening();
79
- };
80
  }
81
 
82
  function startListening() {
@@ -98,17 +94,21 @@ html_code = """
98
 
99
  const utterance = new SpeechSynthesisUtterance(data.response);
100
  speechSynthesis.speak(utterance);
 
 
 
 
101
  } catch (error) {
102
  response.textContent = 'Error processing your request. Please try again.';
103
- status.textContent = 'Error occurred. Please press the mic button to restart.';
104
- isConversationActive = false;
105
  }
106
  };
107
  setTimeout(() => mediaRecorder.stop(), 5000);
108
  mediaRecorder.start();
109
  }).catch(() => {
110
  status.textContent = 'Microphone access denied.';
111
- isConversationActive = false;
112
  });
113
  }
114
  </script>
 
61
  const micButton = document.getElementById('mic-button');
62
  const status = document.getElementById('status');
63
  const response = document.getElementById('response');
64
+ let isListening = false;
65
 
66
  micButton.addEventListener('click', () => {
67
+ if (!isListening) {
68
+ isListening = true;
69
  startConversation();
70
  }
71
  });
72
 
73
  function startConversation() {
74
+ status.textContent = 'Listening...';
75
+ startListening();
 
 
 
 
76
  }
77
 
78
  function startListening() {
 
94
 
95
  const utterance = new SpeechSynthesisUtterance(data.response);
96
  speechSynthesis.speak(utterance);
97
+ utterance.onend = () => {
98
+ isListening = false;
99
+ status.textContent = 'Press the mic button to continue ordering.';
100
+ };
101
  } catch (error) {
102
  response.textContent = 'Error processing your request. Please try again.';
103
+ status.textContent = 'Press the mic button to restart.';
104
+ isListening = false;
105
  }
106
  };
107
  setTimeout(() => mediaRecorder.stop(), 5000);
108
  mediaRecorder.start();
109
  }).catch(() => {
110
  status.textContent = 'Microphone access denied.';
111
+ isListening = false;
112
  });
113
  }
114
  </script>