-
Notifications
You must be signed in to change notification settings - Fork 1
/
minimalMicrophone.html
61 lines (59 loc) · 1.66 KB
/
minimalMicrophone.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<html>
<script>
var audioContext = new AudioContext();
var microphoneStream, delayNode, gainNode;
// Collecting several ways of access.
// As microphone access is not standardized, we have to do
// trials now.
if (!navigator.getUserMedia){
navigator.getUserMedia =
navigator.getUserMedia || navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia || navigator.msGetUserMedia;
}
// did it work?
if (!navigator.getUserMedia){
alert("I did not find a way to access the microphone.");
} else {
// Looks good. Prepare the nodes.
delayNode = audioContext.createDelay(5);
delayNode.delayTime.value = 0;
gainNode = audioContext.createGain();
gainNode.gain.value = 0.75;
delayNode.connect(gainNode)
gainNode.connect(audioContext.destination);
// Now claim the Mike.
navigator.getUserMedia(
// what media are requested
{audio:true},
// what to do when everything works
function(stream) {
microphoneStream = audioContext.createMediaStreamSource(stream);
// plug it in
microphoneStream.connect(delayNode);
},
// what to do when it fails
function(e) {
alert("Error in attempt to access the microphone: "+e);
}
);
};
</script>
<body>
<span>
0 <input id="delay" type="range" min="0" max="5" step="0.1" value="0" oninput="delayNode.delayTime.value = this.value;">
5 Delay
</span>
<br />
<span>
0 <input id="gain" type="range" min="0" max="2" step="0.1" value="0.75" oninput="gainNode.gain.value = this.value;">
2 Gain
</span>
<br />
<p>
Be careful with the gain, you may get feedback soon.
</p>
<p>
Tested with Chrome Version 45.0.2454.101 m.
</p>
</body>
</html>