Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Trigger button based on Voice Command

I am trying to create a voice-controlled website. What I exactly plan to do is say 'hello' to trigger the button 'Open WebCam'. I am using Annyang for processing my voice commands and simple javascript selectors to open the webcam. But even though, these two work fine separately but every time I try to integrate these two for the final result, I get stuck.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Voice Control</title>
</head>
<style>
    div {
      width: 500px;
      height: 400px;
      border: 2px solid black;
      position: relative;
    }
    video {
      width: 500px;
      height: 400px;
      object-fit: cover;
    }
  </style>
<body>
    <center>
        <div>
          <video id="vid"></video>
        </div>
        <br />
        <button id="but" autoplay>
          Open WebCam
        </button>
      </center>
</body>
<script src="//cdnjs.cloudflare.com/ajax/libs/annyang/2.6.1/annyang.min.js"></script>
<script>

    if(annyang) {
        var commands = {
            'hello': function() { 
document.addEventListener("DOMContentLoaded", () => {
                        var but = document.getElementById("but");
                        var video = document.getElementById("vid");
                        var mediaDevices = navigator.mediaDevices;
                        vid.muted = true;
                        but.addEventListener("click", () => {
                
                        // Accessing the user camera and video.
                        mediaDevices
                        .getUserMedia({
                        video: true,
                        audio: true,
                        })
                        .then((stream) => {
            
                        // Changing the source of video to current stream.
                        video.srcObject = stream;
                        video.addEventListener("loadedmetadata", () => {
                            video.play();
                        });
                        })
                        .catch(alert);
                    });
                });
        }
        };
        annyang.addCommands(commands);
        annyang.start();
    }
</script>

</html>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!