为什么使用 MediaElementAudioSourceNode 更适合播放较长的声音?

Why is it more suitable to use a MediaElementAudioSourceNode for longer sounds?

完整问题:为什么使用 MediaElementAudioSourceNode 而不是 AudioBuffer 更适合较长的声音?

From MDN:

Objects of these types are designed to hold small audio snippets, typically less than 45 s. For longer sounds, objects implementing the MediaElementAudioSourceNode are more suitable.

From the specification:

This interface represents a memory-resident audio asset (for one-shot sounds and other short audio clips). Its format is non-interleaved 32-bit linear floating-point PCM values with a normal range of [−1,1][−1,1], but values are not limited to this range. It can contain one or more channels. Typically, it would be expected that the length of the PCM data would be fairly short (usually somewhat less than a minute). For longer sounds, such as music soundtracks, streaming should be used with the audio element and MediaElementAudioSourceNode.

  1. 使用 MediaElementAudioSourceNode 而不是 AudioBuffer 有什么好处?
  2. 短片使用MediaElementAudioSourceNode有什么缺点吗?
  1. MediaElementSourceNode 具有流式传输的潜在能力 - 并且肯定会在整个声音文件下载和解码之前开始播放。它还能够在不将声音文件转换(可能扩展!)为 32 位线性 PCM(CD 质量音频每通道仅为 16 位)和转码为输出设备采样率的情况下执行此操作。例如,以 16 位、16kHz 录制的 1 分钟播客本身的大小不到 2 兆字节;如果您在 48kHz 设备上播放(并不少见),转码为 32 位 48kHz 将意味着您使用了将近 12 兆字节作为 AudioBuffer。

  2. MediaElementSourceNode 不会为您提供精确的播放时间,也不会 manage/playback 大量同步声音。对于您的用例,精度可能是合理的,但它不会像 AudioBuffer 那样具有采样精确的时间。