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 console log current directory 
Javascript :: JS copy image 
Javascript :: difference between w component did update and did mount 
Javascript :: convert number to indian rupee format in javascript 
Javascript :: share data between livewire and alpine js 
Javascript :: mongoose model and joi validation 
Javascript :: macam macam looping javascript 
Javascript :: javascript Remove Element from Outer Array 
Javascript :: json api data fetch error 
Javascript :: next greater element javascript using stack 
Javascript :: onClick button react send to another component 
Javascript :: setup neovim vscode jj hotkey 
Python :: ignore warnings 
Python :: python open link in browser 
Python :: pygame boilerplate 
Python :: max columns in python 
Python :: install reportlab python 
Python :: save utf 8 text file in python 
Python :: cv2.cvtcolor grayscale 
Python :: blink raspberry pico 
Python :: python delay 
Python :: tqdm pandas apply in notebook 
Python :: keras plot history 
Python :: set recursion limit python 
Python :: use incognito mode in selenium 
Python :: pandas rename specific column 
Python :: add picture to jupyter notebook 
Python :: python simple server 
Python :: list files in s3 folder python 
Python :: pandas read_csv ignore first column 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =