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-javascriptjavascript