Skip to content

Commit

Permalink
Added recordAsMP3 functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sb2702 committed Jun 19, 2015
1 parent e4793b4 commit 6afb843
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 145 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ Example:
- **bufferLen** - The length of the buffer that the internal JavaScriptNode uses to capture the audio. Can be tweaked if experiencing performance issues. Defaults to 4096.
- **callback** - A default callback to be used with `exportWAV`.
- **type** - The type of the Blob generated by `exportWAV`. Defaults to 'audio/wav'.
- **recordAsMP3** - Binary: if true - will continuously encode the stream into mp3 format, making MP3 exports much faster, especially for recordings of over 10 seconds. Defaults to false


**TODO** continuously encoding OGG provides a codec error, figure out why

---------
#### Instance Methods
Expand Down
34 changes: 30 additions & 4 deletions example/index.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<!DOCTYPE html>

<html>


<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Live input record and playback</title>
Expand All @@ -11,6 +13,7 @@
<link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div></div>

<h1>Audio Recording test</h1>

Expand Down Expand Up @@ -61,12 +64,24 @@ <h2>Log</h2>
__log('Exporting to OGG');




var c = Date.now();



recorder.exportOGG(function(blob) {


var a = Date.now();


__log('OGG file successfully exported');

console.log("Ogg file successfully exported");

__log('OGG Processed in ' + (a -c) + 'ms' );




console.log(blob);
Expand All @@ -88,12 +103,24 @@ <h2>Log</h2>




__log('Exporting to mp3');
recorder.exportMP3(function(blob) {


var b = Date.now();

recorder.exportMP3(function(blob) {

__log('MP3 file successfully exported');

var a = Date.now();

__log('MP3 Processed in ' + (a -b) + 'ms' );


var length = ((blob.size*8)/128000);

__log('MP3 duration: ' +length + ' s' );

console.log(blob);
var url = URL.createObjectURL(blob);
Expand All @@ -119,7 +146,6 @@ <h2>Log</h2>




});


Expand All @@ -133,7 +159,7 @@ <h2>Log</h2>
audioRecorder.requestDevice(function(recorderObject){

recorder = recorderObject;
});
}, {recordAsOGG: true});



Expand Down
26 changes: 5 additions & 21 deletions example/js/audioRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
var recording = false, initialized=false,
currCallback, worker;

console.log("Recorder Object");

var bufferLen = config.bufferLen || 4096;
this.context = source.context;
this.node = (this.context.createScriptProcessor ||
Expand All @@ -30,7 +28,9 @@
config: {
sampleRate: this.context.sampleRate,
mp3LibPath: mp3LibPath,
vorbisLibPath: vorbisLibPath
vorbisLibPath: vorbisLibPath,
recordAsMP3: config.recordAsMP3 || false,
recordAsOGG: config.recordAsOGG || false
}
});

Expand Down Expand Up @@ -95,8 +95,6 @@





this.node.onaudioprocess = function(e){
if (!recording) return;
worker.postMessage({
Expand All @@ -113,8 +111,7 @@



};

}



Expand Down Expand Up @@ -145,30 +142,17 @@

}, function(e) {

console.log("An error occurred"); //TODO: Error handling
console.log("An error occurred"); //Null if something goes wrong
callback(null);

});

}



};














window.audioRecorder = audioRecorder;


Expand Down
Loading

0 comments on commit 6afb843

Please sign in to comment.