Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 65 |
|
| 66 |
micButton.addEventListener('click', () => {
|
| 67 |
-
if (!
|
| 68 |
-
|
| 69 |
startConversation();
|
| 70 |
}
|
| 71 |
});
|
| 72 |
|
| 73 |
function startConversation() {
|
| 74 |
-
|
| 75 |
-
|
| 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 = '
|
| 104 |
-
|
| 105 |
}
|
| 106 |
};
|
| 107 |
setTimeout(() => mediaRecorder.stop(), 5000);
|
| 108 |
mediaRecorder.start();
|
| 109 |
}).catch(() => {
|
| 110 |
status.textContent = 'Microphone access denied.';
|
| 111 |
-
|
| 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>
|