简体   繁体   中英

Changing the pitch of the sound of an HTML5 audio node

I would like to change the pitch of a sound file using the HTML 5 Audio node. I had a suggestion to use the setVelocity property and I have found this is a function of the Panner Node I have the following code in which I have tried changing the call parameters, but with no discernible result.

Does anyone have any ideas, please?

I have the folowing code:

var gAudioContext = new AudioContext()
var  gAudioBuffer;
var playAudioFile = function (gAudioBuffer) {
    var panner = gAudioContext.createPanner();
    gAudioContext.listener.dopplerFactor = 1000
    source.connect(panner); 
    panner.setVelocity(0,2000,0);
    panner.connect(gainNode);
    gainNode.connect(gAudioContext.destination);
    gainNode.gain.value = 0.5

    source.start(0); // Play sound 

};

var loadAudioFile = (function (url) {
    var request = new XMLHttpRequest();
    request.open('get', 'Sounds/English.wav', true);
    request.responseType = 'arraybuffer';
    request.onload = function () {
            gAudioContext.decodeAudioData(request.response,
                 function(incomingBuffer) {
                     playAudioFile(incomingBuffer);
                 }
            );
    };
    request.send();
}());

I'm trying to achieve something similar and I also failed at using PannerNode.setVelocity() . One working technique I found is by using the following package (example included in the README): https://www.npmjs.com/package/soundbank-pitch-shift

It is also possible with a biquad filter, available natively. See an example here: http://codepen.io/qur2/pen/emVQwW I didn't find a simple sound to make it obvious (CORS restriction with ajax loading). You can read more at http://chimera.labs.oreilly.com/books/1234000001552/ch04.html and https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode .

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM