为什么我的警报和提示无法正常工作?

时间:2018-04-02 22:16:50

标签: javascript function alert delay webcam

为什么我的警报和提示都没有工作?警报也设置为音频,因为音频,警报和提示都设置在延迟音频功能中。虽然我似乎无法让他们玩网络摄像头功能。网络摄像头包括一个跟踪面部功能,它占用了大量额外的绒毛代码。

但我似乎无法找到一个地方来调用警报功能'delayedAlert'而不会分发网络摄像头,使其不显示。

我对javascript很新,所以基本上我知道很少/没有。所以只是代码示例,因为否则我不会理解。

      <script>

    var timeoutID;

    function delayedAlert() {
      timeoutID = window.setTimeout(slowAlert, 5000);
    }

    function slowAlert() {
     var audio= document.getElementsByTagName('audio')[0];
     const audio2 = document.getElementsByTagName('audio')[1];
     var audio3 = document.getElementsByTagName('audio')[2];
      var audio4 = document.getElementsByTagName('audio')[3];

    audio.play(); 
    var myvar1;alert('Hello?');

    audio2.play(); 
    var myvar1;alert('Is something here?');

    audio3.play();
    var myvar2;alert('Something is here.');

    audio4.play();

    const name = prompt('What is your name?')

    const sentence = 'Hello,' + name +'.I am Eve. ....'+name+name+name+'.'+name+'is human...Ive never seen a. human....What does' +name +' look like?';
    responsiveVoice.speak(sentence, "US English Female", {
        rate: 0.7,
      onend: function() {
        // Redirect after sentence has been spoke
        location.replace('https://www.eves.website/eve_2.html');
      }
    });
    };
          window.onload = function() {
          var video = document.getElementById('video');
          var canvas = document.getElementById('canvas');
          var context = canvas.getContext('2d');
          var inverse = function inverse(imageData) {
        var data = imageData.data;
        for (var i = 0; i < data.length; i += 4) {
            data[i] = 255 - data[i];
            data[i + 1] = 255 - data[i + 1];
            data[i + 2] = 255 - data[i + 2];
        }
        return imageData;
    };
          var tracker = new tracking.ObjectTracker('face');
          tracker.setInitialScale(4);
          tracker.setStepSize(2);
          tracker.setEdgesDensity(0.1);

          tracking.track('#video', tracker, { camera: true });

          tracker.on('track', function(event) {
            context.clearRect(0, 0, canvas.width, canvas.height);

            event.data.forEach(function(rect) {
              context.strokeStyle = '#0000ff';
              context.strokeRect(rect.x, rect.y, rect.width, rect.height);
              context.font = '13px Helvetica';
              context.fillStyle = "#fff";
              context.fillText('x: ' + rect.x + '3px', rect.x + rect.width + 5, rect.y + 11);
              context.fillText('y: ' + rect.y + '3px', rect.x + rect.width + 5, rect.y + 22);
            });
          });

          var gui = new dat.GUI();
          gui.add(tracker, 'edgesDensity', 0.5, 0.5).step(0.1);
          gui.add(tracker, 'initialScale', 1.0, 10.0).step(0.1);
          gui.add(tracker, 'stepSize', 1, 5).step(0.1);
        };


        </script>
        </head>
        <body>

      <div class="demo-frame">
        <div class="demo-container">
          <video id="video" width="700" height="700" preload autoplay loop muted></video>
          <canvas id="canvas" width="700" height="700"></canvas>
        </div>
      </div>

     <audio>
      <source src="../audio/hello.wav" type="audio/wav" preload=true>
     </audio>

     <audio>
      <source src="../audio/is_something_here.wav" type="audio/wav" preload=true>
     </audio>

      <audio>
      <source src="../audio/oh_something_is_here.wav" type="audio/wav" preload=true>
     </audio>


     <audio>
     <source src="../audio/what_is_your_name.wav" type="audio/wav" preload=true>
     </audio>

    </body>
    </html>

0 个答案:

没有答案