-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummary.js
More file actions
92 lines (77 loc) · 2.96 KB
/
summary.js
File metadata and controls
92 lines (77 loc) · 2.96 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
function Summary(audio) {
this.audio = audio;
var recorder;
init()
function init() {
var imported = document.createElement('script');
imported.src = '/RecordRTC.js';
document.head.appendChild(imported);
}
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.');
console.error(error);
});
}
function startRecording(chunkCallback) {
chunkCallback = chunkCallback || function() {};
captureMicrophone(function(microphone) {
audio.srcObject = microphone;
recorder = RecordRTC(microphone, {
type: 'audio',
recorderType: StereoAudioRecorder,
mimeType: 'audio/wav',
timeSlice: 500,
desiredSampRate: 16000,
bufferSize: 8192,
numberOfAudioChannels: 1,
ondataavailable: function(blob) {
chunkCallback(blob)
}
});
recorder.startRecording();
// release microphone on stopRecording
recorder.microphone = microphone;
});
}
function stopRecording(callback) {
callback = callback || function() {};
recorder.stopRecording(function() {
stopRecordingCallback()
callback()
});
}
function stopRecordingCallback() {
// ------------------------------------------------------------
// get access to StereoAudioRecorder object (name as "internal-recorder")
// ------------------------------------------------------------
var internalRecorder = recorder.getInternalRecorder();
// ------------------------------------------------------------
// get left and right audio channels
// ------------------------------------------------------------
var leftchannel = internalRecorder.leftchannel;
var rightchannel = internalRecorder.rightchannel;
// ------------------------------------------------------------
// create your own WAV
// ------------------------------------------------------------
internalRecorder.stop(function(buffer, view) {
// ------------------------------------------------------------
// here is your own WAV (generated by your own codes)
// ------------------------------------------------------------
var blob = new Blob([buffer], {
type: 'audio/wav'
});
audio.srcObject = null;
audio.src = URL.createObjectURL(blob);
});
recorder.microphone.stop();
}
return {
"startRecording": startRecording,
"stopRecording": stopRecording
}
}