Sound playback for a short beep effect

Hello, Loving the React Studio software for my project.

My current new feature is that I am trying to playback a short beep sound effect in my web app when a new chat message appears. I imagine this might be difficult, since it might have to play audio across multiple devices and browsers. Would this even be possible?

I actually got the start of something working for this based on some code I found online.

var audioCtx = new (window.AudioContext || window.webkitAudioContext || window.audioContext);

function beep(duration, frequency, volume) {
  if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
   //do nothing when mobile
  } else {
    var oscillator = audioCtx.createOscillator();
    var gainNode = audioCtx.createGain();


    if (volume){gainNode.gain.value = volume;}
    if (frequency){oscillator.frequency.value = frequency;}
  	oscillator.onended = function() { }
  	oscillator.stop(audioCtx.currentTime + ((duration || 250) / 1000));

Then I call it with.


1 Like