Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript make beep sound

function beep() {
  var context = new AudioContext();
  var oscillator = context.createOscillator();
  oscillator.type = "sine";
  oscillator.frequency.value = 800;
  oscillator.connect(context.destination);
  oscillator.start(); 
  // Beep for 500 milliseconds
  setTimeout(function () {
      oscillator.stop();
  }, 500);
}

beep();

// See source for a parametrized sound
Comment

Beep sound Javascript

//if you have another AudioContext class use that one, as some browsers have a limit
var audioCtx = new (window.AudioContext || window.webkitAudioContext || window.audioContext);

//All arguments are optional:

//duration of the tone in milliseconds. Default is 500
//frequency of the tone in hertz. default is 440
//volume of the tone. Default is 1, off is 0.
//type of tone. Possible values are sine, square, sawtooth, triangle, and custom. Default is sine.
//callback to use on end of tone
function beep(duration, frequency, volume, type, callback) {
    var oscillator = audioCtx.createOscillator();
    var gainNode = audioCtx.createGain();

    oscillator.connect(gainNode);
    gainNode.connect(audioCtx.destination);

    if (volume){gainNode.gain.value = volume;}
    if (frequency){oscillator.frequency.value = frequency;}
    if (type){oscillator.type = type;}
    if (callback){oscillator.onended = callback;}

    oscillator.start(audioCtx.currentTime);
    oscillator.stop(audioCtx.currentTime + ((duration || 500) / 1000));
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript determine array type 
Javascript :: next js active link 
Javascript :: react native get numeric random string length of 5 characters 
Javascript :: Get current active sheet name google appscript 
Javascript :: js time difference in minutes 
Javascript :: fs get random file in folder 
Javascript :: javascript check empty object 
Javascript :: ajax post 
Javascript :: max value in array javascript 
Javascript :: jquery select radio by name 
Javascript :: google maps js on map load 
Javascript :: get the sum of Json values javascript 
Javascript :: get columns of array list json js 
Javascript :: jquery minified cdn 
Javascript :: createdAt 
Javascript :: remover o primeiro caracter de uma string javascript 
Javascript :: find div height in javascript 
Javascript :: get select option selected text jquery 
Javascript :: how to check if a number is float javascript 
Javascript :: node parameter add memory 
Javascript :: edit json via nodejs 
Javascript :: how to trigger events when the document loads in js 
Javascript :: javascript loop thrown object 
Javascript :: document getelementsbyclassname not getting all elements 
Javascript :: integer check in javascript 
Javascript :: react absolute path 
Javascript :: file input disable open file picker javascript 
Javascript :: change logo sapui5 
Javascript :: angular readonly/Disabled if value is not null 
Javascript :: Javascript case insensitive string comparison 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =