Skip to content

Commit e3f7ebd

Browse files
committed
added getBuffer
1 parent 996955b commit e3f7ebd

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ This will generate a Blob object containing the recording in WAV format. The cal
3737

3838
In addition, you may specify the type of Blob to be returned (defaults to 'audio/wav').
3939

40+
rec.getBuffer([callback])
41+
42+
This will pass the recorded buffer (as a Float32Array) to the callback. It can be played back by creating a new source buffer and setting this as its channel data (i.e. `newSource.buffer.getChannelData(0).set(recordedBuffer)`).
43+
4044
rec.configure(config)
4145

4246
This will set the configuration for Recorder by passing in a config object.

recorder.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
worker.postMessage({ command: 'clear' });
4949
}
5050

51+
this.getBuffer = function(cb) {
52+
currCallback = cb || config.callback;
53+
worker.postMessage({ command: 'getBuffer' })
54+
}
55+
5156
this.exportWAV = function(cb, type){
5257
currCallback = cb || config.callback;
5358
type = type || config.type || 'audio/wav';

recorderWorker.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ this.onmessage = function(e){
1313
case 'exportWAV':
1414
exportWAV(e.data.type);
1515
break;
16+
case 'getBuffer':
17+
getBuffer();
18+
break;
1619
case 'clear':
1720
clear();
1821
break;
@@ -39,6 +42,11 @@ function exportWAV(type){
3942
this.postMessage(audioBlob);
4043
}
4144

45+
function getBuffer() {
46+
var buffer = mergeBuffers(recBuffers, recLength)
47+
this.postMessage(buffer);
48+
}
49+
4250
function clear(){
4351
recLength = 0;
4452
recBuffers = [];

0 commit comments

Comments
 (0)