var audioSrc = 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/1715/the_xx_-_intro.mp3';

function bufferSound(ctx, url) {
  var p = new Promise(function(resolve, reject) {
    var req = new XMLHttpRequest();
    req.open('GET', url, true);
    req.responseType = 'arraybuffer';
    req.onload = function() {
      ctx.decodeAudioData(req.response, resolve, reject);
    }
    req.send();
  });
  return p;
}

var audioContext = new AudioContext();
bufferSound(audioContext, audioSrc).then(function (buffer) {
    var g = audioContext.createGain();
    g.gain.value = 5;
    g.connect(audioContext.destination);

    var bq = audioContext.createBiquadFilter();
    // found out about detune here: http://chimera.labs.oreilly.com/books/1234000001552/ch04.html
    bq.detune.value = 1200;
    bq.connect(g);

    var src = audioContext.createBufferSource();
    src.buffer = buffer;
    src.connect(bq);

    src.start();
});
<label for="pitchIn">Set pitch</label>
<input type="number" min="-1200" max="1200" step="200" value="0" id="pitchIn">

其他参考:https://stackoverflow.com/questions/53876757/how-to-change-the-pitch-with-javascript

相关文章:

  • 2021-10-12
  • 2023-01-16
  • 2021-12-15
  • 2021-12-11
  • 2021-11-14
  • 2021-07-20
  • 2022-03-10
  • 2021-07-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
  • 2021-08-13
  • 2021-09-23
  • 2021-11-01
相关资源
相似解决方案