noteOn 不是函数

noteOn is not a function

我有:

          if ('webkitAudioContext' in window) {
            ctx = new webkitAudioContext()
          } else if ('AudioContext' in window) {
            ctx = new AudioContext()
          } else {
            console.log('Web Audio API is not available.')
          }
          audioHuman = document.getElementById("human")
          sourceHuman = ctx.createMediaElementSource(audioHuman)
          sourceHuman.connect(ctx.destination)
          

但是我在这里得到一个错误:

sourceHuman.noteOn(0)

Uncaught TypeError: sourceHuman.noteOn is not a function

为什么noteOn方法没有定义?

更新

我正在使用我的 HTML 音频标签通过 hls.js 进行流式传输:

    <audio id="human" preload="metadata" playsinline>
      <source src="media/human/playlist.m3u8">
      <source src="media/human.m4a" type="audio/mpeg">
      <source src="media/human.ogg" type="audio/ogg">
      <source src="media/human.mp3" type="audio/mpeg">
      Your browser does not support the audio tag.
    </audio>
function setupHls(media, mediaSrc) {
      if (Hls.isSupported()) { // Check if HLS.js is supported.
        var hls = new Hls()
        hls.loadSource(mediaSrc)
        hls.attachMedia(media)
      } else if (media.canPlayType('application/vnd.apple.mpegurl')) { // Check for native browser HLS support.
        media.src = mediaSrc
      } else {
        console.log("Your browser doesn't support HTTP Live Streaming.")
      }
    }

setupHls(document.getElementById("human"), 'media/human/playlist.m3u8')

我想获取通过 HLS 流式传输的音频并使用 Web 音频对其进行处理 API。

根据this post, I guess I would have to use MediaElementAudioSourceNode。但我不太确定如何。

更新

通过将输出记录到控制台,我了解到 MediaElementAudioSourceNode is actually the output type of the createMediaElementSource 方法。

正如@DDomen 所指出的,我不明白的是 HTML5 <audio> 元素 play/pause/stop 方法对于 AudioContext 仍然有效:

Note: As a consequence of calling createMediaElementSource(), audio playback from the HTMLMediaElement will be re-routed into the processing graph of the AudioContext. So playing/pausing the media can still be done through the media element API and the player controls.