By creating an Audio object you can play sounds. In this example a sound will play when I press the Left Arrow key. If you don't hear anything try to find a different link. Only .wav files have been tested. Another note; when creating the Audio object, wrap it inside a function like in this example.


var subtitle = "";

var playSound = function(){
    var url = "http://www.wavsource.com/snds_2018-01-14_3453803176249356/sfx/applause_y.wav";
    var applause = new Audio(url);
    if(keyCode === LEFT){
        applause.play();
        subtitle = "Applause";
    }
};

var keyPressed = function()  {
    background(255);
    playSound();  
    fill(0);
    textSize(50);
    textAlign(CENTER,CENTER);
    text(subtitle,200,200);
};