Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add voice command feature #542

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions voice_command.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AmbuFlow Voice Command</title>
</head>
<body>
<h1>AmbuFlow Voice Command</h1>
<button id="start-record-btn">Start Voice Command</button>
<p id="result"></p>

<script>
document.getElementById('start-record-btn').addEventListener('click', function() {
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();

recognition.lang = 'en-US'; // Set the language
recognition.interimResults = false; // Final results only

recognition.onstart = function() {
console.log('Voice recognition started. Speak into the microphone.');
document.getElementById('result').innerText = 'Listening...';
};

recognition.onresult = function(event) {
const transcript = event.results[0][0].transcript.toLowerCase();
document.getElementById('result').innerText = `You said: "${transcript}"`;

if (transcript.includes('help me find an ambulance')) {
alert('Requesting ambulance...');
// Call your function here, e.g., requestAmbulance();
} else if (transcript.includes('locate the nearest hospital')) {
alert('Finding nearest hospital...');
// Call your function here, e.g., findNearestHospital();
} else {
alert('Command not recognized. Please try again.');
}
};

recognition.onerror = function(event) {
console.error('Speech recognition error detected: ' + event.error);
document.getElementById('result').innerText = 'Error occurred in recognition: ' + event.error;
};

recognition.onend = function() {
console.log('Voice recognition ended.');
document.getElementById('result').innerText += ' (Stopped listening)';
};

recognition.start();
});
</script>
</body>
</html>