This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input | |
class="gain-control" | |
type="range" | |
min="0" | |
max="1" | |
step="0.01" | |
value="0.5"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setting target value (1st argument) starting from | |
// the current time in 0.01 second period | |
gainNode.gain.setTargetAtTime(2, context.currentTime, 0.01); | |
// Doing the same but exponentially. | |
gainNode.gain.exponentialRampToValueAtTime(gain, context.currentTime + 0.01); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a gain node and set the initial value to 0.5 | |
// that means that volume will be haft of the original. | |
const gainNode = new GainNode(context, {gain: 0.5}); | |
// Disconnect source before constructing a new graph. | |
lineInSource.disconnect(); | |
// Connect nodes | |
lineInSource.connect(gainNode).connect(context.destination); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lineInSource.disconnect(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const context = new AudioContext(); | |
if (context.state === 'suspended') { | |
await context.resume(); | |
} | |
const stream = await navigator.mediaDevices | |
.getUserMedia({ | |
audio: { | |
echoCancellation: false, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lineInSource = context.createMediaStreamSource(stream); | |
lineInSource.connect(context.destination); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Getting permission status. | |
const micStatus = await navigator.permissions.query({name: 'microphone'}); | |
console.log(micStatus); // state: "prompt" | |
// Reset permission to initial state. | |
await navigator.permissions.revoke({name: 'microphone'}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stream = await navigator.mediaDevices | |
.getUserMedia({ | |
audio: { | |
echoCancellation: false, | |
autoGainControl: false, | |
noiseSuppression: false, | |
latency: 0 | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stream = await navigator.mediaDevices | |
.getUserMedia({audio: true}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (context.state === 'suspended') { | |
await context.resume(); | |
} |