-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathedge-audio-recording.html
71 lines (56 loc) · 2.15 KB
/
edge-audio-recording.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
62
63
64
65
66
67
68
69
70
71
<style>
html, body {
margin: 0!important;
padding: 0!important;
}
</style>
<title>MS-Edge Audio Recording using RecordRTC</title>
<h1>MS-Edge Audio Recording using RecordRTC</h1>
<br>
<button id="btn-start-recording">Start Recording</button>
<button id="btn-stop-recording" disabled>Stop Recording</button>
<hr>
<audio controls autoplay playsinline></audio>
<script src="/RecordRTC.js"></script>
<script>
var audio = document.querySelector('audio');
function captureMicrophone(callback) {
navigator.mediaDevices.getUserMedia({audio: true}).then(function(microphone) {
callback(microphone);
}).catch(function(error) {
alert('Unable to capture your microphone. Please check console logs. Please make sure to enable Windows Start Button => Settings => Privacy => Camera+Microphone for Edge browser.');
console.error(error);
});
}
function stopRecordingCallback() {
audio.srcObject = null;
var blob = recorder.getBlob();
audio.src = URL.createObjectURL(blob);
recorder.microphone.stop();
}
var isEdge = navigator.userAgent.indexOf('Edge') !== -1 && (!!navigator.msSaveOrOpenBlob || !!navigator.msSaveBlob);
var recorder; // globally accessible
document.getElementById('btn-start-recording').onclick = function() {
this.disabled = true;
captureMicrophone(function(microphone) {
audio.srcObject = microphone;
recorder = RecordRTC(microphone, {
type: 'audio',
recorderType: StereoAudioRecorder, // this line is required for MS-Edge
// sampleRate: 44100,
numberOfAudioChannels: isEdge ? 1 : 2,
// bufferSize: 16384
});
recorder.startRecording();
// release microphone on stopRecording
recorder.microphone = microphone;
document.getElementById('btn-stop-recording').disabled = false;
});
};
document.getElementById('btn-stop-recording').onclick = function() {
this.disabled = true;
recorder.stopRecording(stopRecordingCallback);
};
</script>
<footer style="margin-top: 20px;"><small id="send-message"></small></footer>
<script src="https://www.webrtc-experiment.com/common.js"></script>