Home > Web Front-end > HTML Tutorial > Real-time sound generation using JavaScript/HTML5

Real-time sound generation using JavaScript/HTML5

PHPz
Release: 2023-09-15 09:29:06
forward
1442 people have browsed it

Real-time sound generation using JavaScript/HTML5

The Web Audio API is used to control audio, allowing you to select the audio source. You can also add effects; create audio visualizations, panning, and more.

Example

You can try running the following code snippet to generate the 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
Copy after login

The above is the detailed content of Real-time sound generation using JavaScript/HTML5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template