The simplest way would be to include it in whatever event listener you're using to toggle the element's display value.
When hiding (i.e. $(".deley").hide();
:
$("#epicSound").pause();
$('#epicSound").currentTime = 0;
When showing (i.e. $('.deley').show()
):
$("#epicSound").play();
Your code:
<script type="text/javascript">
$(document).ready(function(){
$(".deley").hide();
// if sound is currently playing, stop it and reset
if(!$("#epicSound").paused) {
$("#epicSound").pause();
$("#epicSound").currentTime = 0;
}
setTimeout(function () {
$(".deley").show();
$("#epicSound").play();
}, 5000);
});
</script>
<div class="deley">TEXT</div>
<audio id="epicSound">
<source src="epicSound.ogg" type="audio/ogg">
<source src="epicSound.mp3" type="audio/mpeg">
</audio>