Home › Forums › General Questions › Trigger a click with the mic of a phone
- This topic has 1 reply, 1 voice, and was last updated 2 months, 3 weeks ago by blippypixel.
-
AuthorPosts
-
2024-09-27 at 6:07 am #77688blippypixelCustomer
Hi there
I used to like Google Cardboard……..everyone could use it with their phones
I wanted to build some kind of paint app in a 3d environment onto a canvas.
I wanted to trigger the mouse click with a sound from the person’s mouth like a sssss. When they stop the sound the click off is triggered.
So you control the cursor with your head and a sound.
What’s the best way of going about this in Verge 3d if that is possible please?
Thanks!2024-09-27 at 6:15 am #77689blippypixelCustomerI asked Chat GPT and it produced this code. I wasn’t sure how to integrate it or get the click into Verge 3d. Any help is greatly appreciated. Thank you
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Voice-Triggered Click</title>
</head>
<body><button id=”myButton”>Click me</button>
<script>
// Function to trigger a click on the button
function triggerClick() {
document.getElementById(‘myButton’).click();
}// Check if browser supports Web Speech API
if (‘webkitSpeechRecognition’ in window || ‘SpeechRecognition’ in window) {
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
const recognition = new SpeechRecognition();recognition.continuous = true; // Keep listening for multiple commands
recognition.interimResults = false; // Don’t display partial results
recognition.lang = ‘en-US’; // Set language// Start recognition
recognition.start();recognition.onresult = function(event) {
// Get the recognized speech
const transcript = event.results[event.resultIndex][0].transcript.trim().toLowerCase();console.log(‘Recognized speech:’, transcript);
// If the recognized command is ‘click’, trigger the click event
if (transcript === ‘click’) {
triggerClick();
}
};recognition.onerror = function(event) {
console.error(‘Speech recognition error:’, event.error);
};} else {
console.error(‘Web Speech API is not supported in this browser.’);
}// Optional: add a listener to show feedback for manual clicks
document.getElementById(‘myButton’).addEventListener(‘click’, function() {
alert(‘Button was clicked!’);
});
</script></body>
</html> -
AuthorPosts
- You must be logged in to reply to this topic.