Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda