-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathencoder.html
140 lines (112 loc) · 4.21 KB
/
encoder.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ogg Opus Encoder Example</title>
<script src="/node_modules/opus-recorder/build/recorder.min.js"></script>
<style type='text/css'>
ul { list-style: none; }
li { margin: 1em; }
audio { display: block; }
</style>
</head>
<body>
<h1>Encoder example</h1>
<p>Before you enable monitoring, make sure to either plug in headphones or turn the volume down.</p>
<p>This ogg opus implementation does not support more than 2 channels.</p>
<h2>Options</h2>
<div>
<label>monitorGain</label>
<input id="monitorGain" type="number" value="0" />
</div>
<div>
<label>numberOfChannels</label>
<input id="numberOfChannels" type="number" value="1" />
</div>
<div>
<label>encoderSampleRate</label>
<input id="encoderSampleRate" type="number" value="48000" />
</div>
<div>
<label>bitRate</label>
<input id="bitRate" type="number" value="64000" />
</div>
<h2>Commands</h2>
<button id="init">init</button>
<button id="start" disabled>start</button>
<button id="pause" disabled>pause</button>
<button id="resume" disabled>resume</button>
<button id="stopButton" disabled>stop</button>
<h2>Recordings</h2>
<ul id="recordingslist"></ul>
<h2>Log</h2>
<pre id="log"></pre>
<script>
var recorder;
start.addEventListener( "click", function(){ recorder.start(); });
pause.addEventListener( "click", function(){ recorder.pause(); });
resume.addEventListener( "click", function(){ recorder.resume(); });
stopButton.addEventListener( "click", function(){ recorder.stop(); });
init.addEventListener( "click", function(){
if (!Recorder.isRecordingSupported()) {
return screenLogger("Recording features are not supported in your browser.");
}
recorder = new Recorder({
monitorGain: parseInt(monitorGain.value, 10),
numberOfChannels: parseInt(numberOfChannels.value, 10),
bitRate: parseInt(bitRate.value,10),
encoderSampleRate: parseInt(encoderSampleRate.value,10),
encoderPath: "../build/encoderWorker.min.js"
});
recorder.addEventListener( "start", function(e){
screenLogger('Recorder is started');
init.disabled = start.disabled = resume.disabled = true;
pause.disabled = stopButton.disabled = false;
});
recorder.addEventListener( "stop", function(e){
screenLogger('Recorder is stopped');
init.disabled = false;
pause.disabled = resume.disabled = stopButton.disabled = start.disabled = true;
});
recorder.addEventListener( "pause", function(e){
screenLogger('Recorder is paused');
init.disabled = pause.disabled = start.disabled = true;
resume.disabled = stopButton.disabled = false;
});
recorder.addEventListener( "resume", function(e){
screenLogger('Recorder is resuming');
init.disabled = start.disabled = resume.disabled = true;
pause.disabled = stopButton.disabled = false;
});
recorder.addEventListener( "streamError", function(e){
screenLogger('Error encountered: ' + e.error.name );
});
recorder.addEventListener( "streamReady", function(e){
init.disabled = pause.disabled = resume.disabled = stopButton.disabled = true;
start.disabled = false;
screenLogger('Audio stream is ready.');
});
recorder.addEventListener( "dataAvailable", function(e){
var dataBlob = new Blob( [e.detail], { type: 'audio/ogg' } );
var fileName = new Date().toISOString() + ".ogg";
var url = URL.createObjectURL( dataBlob );
var audio = document.createElement('audio');
audio.controls = true;
audio.src = url;
var link = document.createElement('a');
link.href = url;
link.download = fileName;
link.innerHTML = link.download;
var li = document.createElement('li');
li.appendChild(link);
li.appendChild(audio);
recordingslist.appendChild(li);
});
recorder.initStream();
});
function screenLogger(text, data) {
log.innerHTML += "\n" + text + " " + (data || '');
}
</script>
</body>
</html>