使用Web Audio API无法获得基本振荡器来产生噪音?

时间:2017-04-26 22:11:56

标签: javascript web-audio-api

无法让振荡器产生噪音?我想我错过了一些显而易见但却不知道的东西。关注https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createOscillator

<!DOCTYPE html>
<html>
  <head>
    <title>Audio API</title>
  </head>
  <body>
    <script>
      var audioContext = new (window.AudioContext || window.webkitAudioContext)();

      var oscillator = audioContext.createOscillator();

      oscillator.type = 'square';
      oscillator.frequency.value = 3000;
      oscillator.start();
    </script>
  </body>
</html>

1 个答案:

答案 0 :(得分:1)

您需要将振荡器节点连接到音频目标:

 oscillator.frequency.value = 3000;
 oscillator.connect( audioContext.destination );
 oscillator.start();