I hope this helps, you can try this code, is vanilla JS but is working, the audio plays when you press Enter keyword (keycode 13). Good luck with your proyect!
var audio = document.getElementById('audio');
window.addEventListener("keydown", function(event) {
if (event.keyCode === 13) {
audio.play();
};
});
i hope my code trigger the audio when user just press the key on keyboard.
At first time? it’s Okay.
but if i frequently pressed some key, the audio was triggered slowly.
This is my html code, loading the audio file.
<audio src = "./src/PMLF_Snare_02.wav" id = "audio"></audio>
and this is my javascript code which triggers audio file.
$(function(){
var audio = document.getElementById('audio');
// Key Down
window.addEventListener('keydown', function(){
//padding effect
$("#"+event.key).css('padding',' 4px 5px 4px 5px');
//play sound
audio.pause();
audio.currentTime = 0;
audio.play();
});
'
'
(skip)
'
'
});
does my code load audio file whenever key is pressed?
how can i get the fast reaction sound like this site?