how to make onclick the sound start only on a side of the earphones
like for example right or left.
something like this: https://www.onlinemictest.com/sound-test/
so if it plays the sound on the left it, the right earphone doesn't need to make any sound.
I think it can be done by using volumes or something like that. how to do that?
(I can't edit the sound in a video editor, I want it will automatically done by javascript)
function playSound(options) {
const choosedDirection = () => {
return Object.keys(options)
.reverse()
.find(
(direction) => direction === "left" || direction === "right",
);
};
const audio = new Audio("audio.mp3");
switch (choosedDirection()) {
case "left":
audio.play();
// how to make here play only on the left side
// by making the volume high on the left and 0 on the right
break;
case "right":
audio.play();
// how to make here play only on the right side
// by making the volume high on the right and 0 on the left
break;
}
}
<head>
<script src="https://cdn.tailwindcss.com/"></script>
</head>
<body class="h-screen grid place-items-center bg-gray-200 overflow-hidden">
<div class="flex gap-[5vmin]">
<div class="flex gap-[5vmin]">
<!-- left -->
<button title=" Left sound" class="transition hover:-translate-y-1 hover:shadow-2xl focus:rotate-3 hover:border-blue-200 hover:shadow-blue-200 focus:border-blue-500 focus:shadow-blue-500 border-4 border-blue-50 shadow-md p-[10vmin] bg-white rounded-[3vmin] text-[10vmin] text-blue-500 after:content-[attr(title)] relative after:absolute after:text-sm after:-bottom-20 after:left-0 after:w-max after:bg-white after:shadow-lg after:-translate-x-[50%] after:left-[50%] after:px-4 after:py-2 after:rounded-lg after:opacity-0 focus:after:opacity-100 focus:after:duration-500 after:translate-y-12 focus:after:translate-y-0 focus:after:animate-pulse focus:animate-bounce"
onclick="playSound({left:true})">
</button>
<!-- right -->
<button title=" Right sound" class="transition hover:-translate-y-1 hover:shadow-2xl focus:rotate-3 hover:border-blue-200 hover:shadow-blue-200 focus:border-blue-500 focus:shadow-blue-500 border-4 border-blue-50 shadow-md p-[10vmin] bg-white rounded-[3vmin] text-[10vmin] text-blue-500 after:content-[attr(title)] relative after:absolute after:text-sm after:-bottom-20 after:left-0 after:w-max after:bg-white after:shadow-lg after:-translate-x-[50%] after:left-[50%] after:px-4 after:py-2 after:rounded-lg after:opacity-0 focus:after:opacity-100 focus:after:duration-500 after:translate-y-12 focus:after:translate-y-0 focus:after:animate-pulse focus:animate-bounce"
onclick="playSound({right:true})">
</button>
</div>
<script>
console.clear(); // not important, just to delete the tailwind warning of using CDN instead of NPM package
</script>
</body>