forked from johanneskropf/node-red-contrib-sox-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sox_record.html
351 lines (341 loc) · 16.9 KB
/
sox_record.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<!--
Copyright 2020, Johannes Kropf
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<script type="text/javascript">
RED.nodes.registerType('sox-record',{
category: 'Sox Utils',
color: '#c28285',
defaults: {
name: {value:""},
buttonStart: {value:"msg", required:true},
inputs: {value:1},
inputSource: {value:"default", required:true},
manualSource: {value:""},
inputEncoding: {value:"signed-integer", required:false},
inputChannels: {value:1, required:false},
inputRate: {value:16000, required:false},
inputBits: {value:16, required:false},
byteOrder: {value:"-L", required:true},
encoding: {value:"signed-integer", required:true},
channels: {value:1, required:true},
rate: {value:16000, required:true},
bits: {value:16, required:true},
gain: {value:"0", required:true},
buffer: {value:"4096", required:true},
showDuration: {value:false, required:true},
durationType: {value:"forever", required:true},
durationLength: {value:"0", required:true},
silenceDetection: {value:"nothing", required:true},
silenceDuration: {value:"2.0", required:true},
silenceThreshold: {value:"2.0", required:true},
outputFormat: {value:"stream", required:true},
manualPath: {value:""},
debugOutput: {value:false, required:true}
},
inputs:1,
outputs:2,
icon: "font-awesome/fa-microphone",
inputLabels: function(index) {
return 'start or stop as msg.payload';
},
outputLabels: function(index) {
if (index === 0) {
switch (this.outputFormat) {
case 'stream':
return 'raw audio buffer stream';
case 'once':
return 'raw audio buffer when finished';
case 'wav':
return 'wav buffer when finished';
case 'file':
return 'file path when finished';
}
} else {
return 'recording progress info';
}
},
label: function() {
return this.name||"sox-record";
},
oneditprepare: function() {
var node = this;
$.getJSON('soxRecord/devices',function(data) {
if (data === "other") {
$("#error").hide();
return;
} else if (data === "error") {
return;
}
$("#notLinux").hide();
$("#error").hide();
data.forEach(device => {
$('#node-input-inputSource').append(`<option value="${device.number}">${device.name}</option>`);
});
$('#node-input-inputSource').val(node.inputSource);
});
$("#node-input-durationType").on("change", function(){
let durVar = $("#node-input-durationType").val();
if(durVar == "limited"){
$("#durationLengthWrapper").show();
} else {
$("#durationLengthWrapper").hide();
}
});
$("#node-input-silenceDetection").on("change", function(){
let silVar = $("#node-input-silenceDetection").val();
if(silVar == "something"){
$("#silenceThresholdWrapper").show();
$("#silenceDurationWrapper").show();
} else {
$("#silenceThresholdWrapper").hide();
$("#silenceDurationWrapper").hide();
}
});
$("#node-input-showDuration").on("change", function(){
if(!$("#node-input-showDuration").prop("checked")){
$("#durationOptionWrapper").hide();
} else {
$("#durationOptionWrapper").show();
}
});
$("#node-input-outputFormat").on("change", function(){
let output = $("#node-input-outputFormat").val();
if(output == "file"){
$("#outputPathWrapper").show();
} else {
$("#outputPathWrapper").hide();
}
});
$("#node-input-buttonStart").on("change", function(){
let value = $("#node-input-buttonStart").val();
if(value === "msg"){
node.inputs = 1;
} else {
node.inputs = 0;
}
});
$("#node-input-inputSource").on("change", function(){
let value = $("#node-input-inputSource").val();
if(value == "fromInput"){
$("#inputFormatWrapper").show();
$("#node-input-buttonStart").val("msg");
$("#node-input-buttonStartRow").hide();
} else if (value == "manualSource") {
$("#manualSourceWrapper").show();
$("#inputFormatWrapper").hide();
$("#node-input-buttonStartRow").show();
} else {
$("#inputFormatWrapper").hide();
$("#node-input-buttonStartRow").show();
}
if (value != "manualSource") { $("#manualSourceWrapper").hide(); }
let value2 = $("#node-input-buttonStart").val();
if(value2 === "msg"){
node.inputs = 1;
} else {
node.inputs = 0;
}
});
},
button: {
enabled: function() {
return !this.changed
},
visible: function() {
let show = (this.buttonStart === "msg") ? false : true;
return show;
},
onclick: function() {
var node = this;
var label = this.name||"sox-record";
$.ajax({
url: "soxRecord/"+this.id+"/record",
type:"POST",
success: function(resp, textStatus, xhr) {
if (xhr.status == 202) {
RED.notify(node._("started recording",{label:label}),"success");
} else if (xhr.status == 200) {
RED.notify(node._("stopped recording",{label:label}),"success");
}
},
error: function(jqXHR,textStatus,errorThrown) {
if (jqXHR.status == 404) {
RED.notify(node._("common.notification.error",{message:node._("common.notification.errors.not-deployed")}),"error");
} else if (jqXHR.status == 500) {
RED.notify(node._("common.notification.error",{message:node._("inject.errors.failed")}),"error");
} else if (jqXHR.status == 0) {
RED.notify(node._("common.notification.error",{message:node._("common.notification.errors.no-response")}),"error");
} else {
RED.notify(node._("common.notification.error",{message:node._("common.notification.errors.unexpected",{status:jqXHR.status,message:textStatus})}),"error");
}
}
});
}
}
});
</script>
<script type="text/html" data-template-name="sox-record">
<div id="error">
<p>Something went wrong. The node couldnt retrieve any devices. The node only runs on Linux with ALSA. If any errors where logged you will find them in the syslog. You can still try and record from the default device or from a raw buffer chunk input.</p>
</div>
<div id="notLinux">
<p>Some features are only available on Linux and with ALSA.</p>
</div>
<div id="error-wrapper">
<h4>Source</h4>
<div class="form-row">
<label for="node-input-inputSource"></i>input source</label>
<select id="node-input-inputSource">
<option value="default">default device</option>
<option value="fromInput">record from a raw audio stream on the nodes input</option>
<option value="manualSource">define input device manually</option>
</select>
</div>
<div class="form-row" id="manualSourceWrapper">
<label for="node-input-manualSource"><i class="icon-tag"></i>manual source input</label>
<input type="text" id="node-input-manualSource" value="" />
</div>
<div class="form-row" id="node-input-buttonStartRow">
<label for="node-input-buttonStart"></i>start/stop</label>
<select id="node-input-buttonStart">
<option value="msg">control with msg.payload</option>
<option value="button">control with button on node</option>
</select>
</div>
<div id="inputFormatWrapper">
<h4>Input Settings</h4>
<div class="form-row">
<label for="node-input-inputEncoding"></i>encoding</label>
<select id="node-input-inputEncoding">
<option value="signed-integer">signed-integer</option>
<option value="unsigned-integer">unsigned-integer</option>
<option value="floating-point">floating-point</option>
</select>
</div>
<div class="form-row">
<label for="node-input-inputChannels"><i class="icon-tag"></i>channels</label>
<input type="number" id="node-input-inputChannels" value="1" />
</div>
<div class="form-row">
<label for="node-input-inputRate"><i class="icon-tag"></i>sample-rate</label>
<input type="number" id="node-input-inputRate" value="16000" />
</div>
<div class="form-row">
<label for="node-input-inputBits"><i class="icon-tag"></i>bit-depth</label>
<input type="number" id="node-input-inputBits" value="16" />
</div>
</div>
<h4>Output Settings</h4>
<div class="form-row">
<label for="node-input-byteOrder"></i>byte order</label>
<select id="node-input-byteOrder">
<option value="-L">little endian</option>
<option value="-B">big endian</option>
</select>
</div>
<div class="form-row">
<label for="node-input-encoding"></i>encoding</label>
<select id="node-input-encoding">
<option value="signed-integer">signed-integer</option>
<option value="unsigned-integer">unsigned-integer</option>
<option value="floating-point">floating-point</option>
</select>
</div>
<div class="form-row">
<label for="node-input-channels"><i class="icon-tag"></i>channels</label>
<input type="number" id="node-input-channels" value="1" />
</div>
<div class="form-row">
<label for="node-input-rate"><i class="icon-tag"></i>sample-rate</label>
<input type="number" id="node-input-rate" value="16000" />
</div>
<div class="form-row">
<label for="node-input-bits"><i class="icon-tag"></i>bit-depth</label>
<input type="number" id="node-input-bits" value="16" />
</div>
<div class="form-row">
<label for="node-input-gain"><i class="icon-tag"></i>gain in dB</label>
<input type="text" id="node-input-gain" value="0" />
</div>
<div class="form-row">
<label for="node-input-buffer"><i class="icon-tag"></i>processing buffer</label>
<input type="text" id="node-input-buffer" value="4096" />
</div>
<h4>Recording Duration</h4>
<div class="form-row">
<label for="node-input-showDuration">duration</i></label>
<input type="checkbox" id="node-input-showDuration" style="display:inline-block; width: auto; vertical-align:baseline;" value="false">
<label for="node-input-showDuration" style="width: 70%;">show options</label>
</div>
<div id="durationOptionWrapper">
<div class="form-row">
<label for="node-input-durationType"><i class="icon-tag"></i>record time</label>
<select id="node-input-durationType">
<option value="forever">record until a stop msg is sent</option>
<option value="limited">record for specified amount of seconds</option>
</select>
</div>
<div id="durationLengthWrapper" class="form-row">
<label for="node-input-durationLength"><i class="icon-tag"></i>seconds</label>
<input type="text" id="node-input-durationLength" value="0.0" />
</div>
<div class="form-row">
<label for="node-input-silenceDetection"><i class="icon-tag"></i>on silence</label>
<select id="node-input-silenceDetection">
<option value="nothing">do nothing</option>
<option value="something">stop recording</option>
</select>
</div>
<div id="silenceDurationWrapper" class="form-row">
<label for="node-input-silenceDuration"><i class="icon-tag"></i>below duration in s</label>
<input type="text" id="node-input-silenceDuration" value="2.0" />
</div>
<div id="silenceThresholdWrapper" class="form-row">
<label for="node-input-silenceThreshold"><i class="icon-tag"></i>below threshold in %</label>
<input type="text" id="node-input-silenceThreshold" value="2.0" />
</div>
</div>
<h4>Output</h4>
<div class="form-row">
<label for="node-input-outputFormat"></i>output format</label>
<select id="node-input-outputFormat">
<option value="stream">a stream of raw buffers while recording</option>
<option value="once">a single raw buffer when recording ends</option>
<option value="wav">a single wav buffer when recording ends</option>
<option value="file">write recorded audio to wav file</option>
</select>
</div>
<div id="outputPathWrapper">
<div class="form-row">
<label for="node-input-manualPath"><i class="icon-tag"></i>output File</label>
<input type="text" id="node-input-manualPath" placeholder="" style="display:inline-block; width: 60%; vertical-align:baseline;">
<label for="node-input-manualPath" id="outputExt" style="width: 10%;">.wav</label>
</div>
<br>
</div>
<div class="form-row">
<label for="node-input-debugOutput"></i>debug</label>
<input type="checkbox" id="node-input-debugOutput" style="display:inline-block; width: auto; vertical-align:baseline;" value="false">
<label for="node-input-debugOutput" style="width: 70%;">detailed debug info to 2nd output</label>
</div>
</div>
<h4>Name</h4>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/html" data-help-name="sox-record">
<p><strong>A simple wrapper node around the record functionality of the sox commandline utility.</strong><br/></p>
<p>The node will record audio on the machine node-red runs on from the configured input source. To start recording send a <code>msg.payload</code> of <strong>start</strong> and to stop it a <code>msg.payload</code> of <strong>stop</strong>. It will output the recorded audio as a buffer in the configured format to the first output as a <code>msg.payload</code> and any recording information or debug info in the <code>msg.payload</code> to its second output.<br/></p>
<p><i>For detailed usage information please go to <a href="https://github.com/johanneskropf/node-red-contrib-sox-utils">node-red-contrib-sox-utils</a>.</i></p>
</script>