| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/API/Web_Audio_API/Using_Web_Audio_API | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
Web Audio API . , , , .
<canvas> <img> , Web Audio API <audio> . . <audio> Web Audio API . , Web Audio API .
Web Audio API " (sound call limitation)" . , 32 64 . 1,000 .
:
, . , .
Web Audio API . API , .
Web Audio API , .
Web Audio API , (modular routing) . , . , , () .
. , .
Web Audio API . API .
//
const AudioContext = window.AudioContext || window.webkitAudioContext;
const audioContext = new AudioContext();
? BaseAudioContext . .
:
, , , OfflineAudioContext .
, . API . , . , , DOM . <audio> .
<audio src="myCoolTrack.mp3"></audio>
:
crossorigin ; Cross Origin Resource Sharing (CORS) .
Web Audio API . AudioContext.createMediaElementSource:
//
const audioElement = document.querySelector("audio");
//
const track = audioContext.createMediaElementSource(audioElement);
, . , , /, , .
JavaScript , ( ) . .
, . Web Audio API .
( ) , . , . :
<button data-playing="false" role="switch" aria-checked="false">
<span>Play/Pause</span>
</button>
/ .
API . , , BaseAudioContext.destination .
track.connect(audioContext.destination);
. :
.
//
const playButton = document.querySelector("button");
playButton.addEventListener(
"click",
function () {
// (suspended) ( )
if (audioContext.state === "suspended") {
audioContext.resume();
}
//
if (this.dataset.playing === "false") {
audioElement.play();
this.dataset.playing = "true";
} else if (this.dataset.playing === "true") {
audioElement.pause();
this.dataset.playing = "false";
}
},
false,
);
. HTMLMediaElement ended , .
audioElement.addEventListener(
"ended",
() => {
playButton.dataset.playing = "false";
},
false,
);
, . Web Audio API . , . GainNode , .
Web Audio API . (: audioContext.createGain()) (constructor) (: new GainNode()). .
const gainNode = audioContext.createGain();
gain , gain :
track.connect(gainNode).connect(audioContext.destination);
:
gain 1; . gain -3.4 3.4 . gain 2 ( 2) 0 ( ) .
<input type="range" id="volume" min="0" max="2" value="1" step="0.01" />
: . .
gain :
const volumeControl = document.querySelector("#volume");
volumeControl.addEventListener(
"input",
function () {
gainNode.gain.value = this.value;
},
false,
);
:
(: GainNode.gain) .
AudioParam .
gain , GainNode.gain value .
, .
, ! gain .
.
StereoPannerNode , , .
:
StereoPannerNode .
PannerNode , , 3D , .
3D .
, .
. , .
const pannerOptions = { pan: 0 };
const panner = new StereoPannerNode(audioContext, pannerOptions);
:
. .
-1 () 1 (). :
<input type="range" id="panner" min="-1" max="1" value="0" step="0.01" />
:
const pannerControl = document.querySelector("#panner");
pannerControl.addEventListener(
"input",
function () {
panner.pan.value = this.value;
},
false,
);
, :
track.connect(gainNode).connect(panner).connect(audioContext.destination);
! '' , , .
. Web Audio API , , .
Web Audio API .
Voice-change-O-matic . , Web Audio API . (Voice-change-O-matic ).
Web Audio API Violent Theremin, (pitch) . (Violent Theremin ).
This page was last modified on 2025 6 27 by MDN contributors.
AnalyserNodeAudioBufferAudioBufferSourceNodeAudioContextAudioDestinationNodeAudioListenerAudioNodeAudioParamAudioProcessingEventAudioScheduledSourceNodeAudioSinkInfoAudioWorkletAudioWorkletGlobalScopeAudioWorkletNodeAudioWorkletProcessorBaseAudioContextBiquadFilterNodeChannelMergerNodeChannelSplitterNodeConstantSourceNodeConvolverNodeDelayNodeDynamicsCompressorNodeGainNodeIIRFilterNodeMediaElementAudioSourceNodeMediaStreamAudioDestinationNodeMediaStreamAudioSourceNodeOfflineAudioCompletionEventOfflineAudioContextOscillatorNodePannerNodePeriodicWaveWaveShaperNodeStereoPannerNodeYour blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |