<h1>Hit start</h1>
<h1>Speak to hear yourself echo</h1>
<h1>Count to 5</h1>
<h1>Switch to a new tab</h1>
<h1>Stay silent for 5 seconds</h1>
<h1>Count to 5 again</h1>
<h1>Notice you don't hear yourself on the other tab</h1>
<h1>Come back to this tab</h1>
<h1>Speak and notice distorted voice</h1>
<h1>Switch tab a few more times with or without counting</h1>
<h1>In every switch speak and notice that distortion is fixed at some point</h1>
<div>
<button id="start-button">Start</button>
</div>
<audio id="audioRef" controls></audio>
JavaScript
let context;
const doStart = async () => {
if (!context)
context = new window.AudioContext();
const audioRef = document.getElementById('audioRef');
let stream;
try {
stream = await window.navigator.mediaDevices.getUserMedia({ audio: true});
} catch (e) {
console.log(e);
return;
}
console.log(`Got stream: ${stream}`);
const source = context.createMediaStreamSource(stream)
const destination = context.createMediaStreamDestination();
// Test example where we pass through input to the audio element.
// This causes distorted audio.
source.connect(destination);
audioRef.srcObject = destination.stream;
audioRef.play();
// Test example where we pass through input to the context destination.
// This works fine.
//source.connect(context.destination);
};
document.getElementById('start-button').onclick = doStart;
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.