
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
Generating sound on the fly with JavaScript/ HTML5
The Web Audio API is used to control audio, which allows you to choose audio sources. You can also add effects; create audio visualizations, panning, etc.
Example
You can try to run the following code snippet to generate sound −
// use one context per document. Here we are creating one context for one document. You can create for other documents also var context = new (window.AudioContext || window.webkitAudioContext)(); // oscillator var os = context.createOscillator(); os.type = 'sine'; // sine is the default. So you can also use square, saw tooth, triangle os.frequency.value = 500; // setting the frequency Hz os.connect(context.destination); // connecting to the destination // starting the oscillator os.start(); os.stop(context.currentTime + 5); // stop 5 seconds after the current time
- Related Articles
- Generating random string with a specific length in JavaScript
- JavaScript File Drop with HTML5
- Can I play the same sound more than once at the same time with HTML5?
- Generating combinations from n arrays with m elements in JavaScript
- Generating desired combinations in JavaScript
- Fill in the following blanks with suitable words:(a) An echo is simply a ............. sound.(b) Pitch of sound depends on ................(c) Loudness of sound depends on .............(d) Quality of sound depends on ................(e) Echoes are caused by the ............. of sound.
- What name is given to those aircrafts which fly at speeds greater than the speed of sound?
- Generating random hex color in JavaScript
- Generating Random Prime Number in JavaScript
- Why would an aircraft be unable to fly on the moon?
- Detection on clicking bezier path shape with HTML5
- Why do birds fly on V shape in the group while travelling?
- Generating random string of specified length in JavaScript
- Generating n random numbers between a range - JavaScript
- Generating all possible permutations of array in JavaScript

Advertisements