<file_sep>const audioContext = new AudioContext();
const $one = document.querySelector("#one");
const $two = document.querySelector("#two");

const audioOne = new Audio();
const audioTwo = new Audio();

$one.addEventListener("click", () => {
  // Play voice
  audioOne.src = "./voice.mp3";
  audioOne.play();

  audioTwo.volume = 0.2;
  audioOne.onended = () => {
    audioTwo.volume = 1;
  };
});

$two.addEventListener("click", () => {
  audioTwo.src = "./music.mp3";
  audioTwo.play();
});
<file_sep># Audio Ducking example

## Working

1. Players `music.mp3`
2. When `voice.mp3` is played, `music.mp3`'s volume is temporarily reduced until done
3. `music.mp3`'s volume goes up again

## Limitations

- Need to pre-download all music and load to the website (could be solved with youtube-dl)
