We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Trigger a click with the mic of a phone

Home Forums General Questions Trigger a click with the mic of a phone

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #77688
    blippypixel
    Customer

    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!

    #77689
    blippypixel
    Customer

    I 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>

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.