Created
March 8, 2015 08:40
-
-
Save faiq/b867998c5fe7fd88a31b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
var tessel = require('tessel') | |
var audio = require('audio-vs1053b') | |
var chunks = []; | |
// When we get data, push it into our array | |
audio.on('data', function(data) { | |
chunks.push(data); | |
}); | |
// Wait for the module to connect | |
audio.on('ready', function() { | |
console.log('Hold the config button to record...'); | |
// When the config button is pressed, start recording | |
tessel.button.once('press', startRecording); | |
}); | |
function startRecording() { | |
// Tell the audio module to start recording | |
audio.startRecording('voice', function() { | |
console.log('Recording...'); | |
// Once the button is released, stop recording | |
tessel.button.once('release', stopRecording); | |
}); | |
} | |
function stopRecording() { | |
// Tell the audio module to stop recording | |
console.log('stopping the recording...'); | |
audio.stopRecording(function() { | |
console.log('Playing it back...'); | |
// Concat the data and play it | |
audio.play(Buffer.concat(chunks), function(err) { | |
// When we're done playing, clear recordings | |
chunks = []; | |
console.log('Hold the config button to record...'); | |
// Wait for a button press again | |
tessel.button.once('press', startRecording); | |
}); | |
}); | |
} | |
// If there is an error, report it | |
audio.on('error', function(err) { | |
throw err; | |
}); | |
/* | |
audio.on('data', function(data) { | |
chunks.push(data) | |
}) | |
audio.on('ready', function () { | |
audio.startRecording('voice', function() { | |
audio.stopRecording('voice', function () { | |
audio.play(Buffer.concat(chunks), function(err) { | |
chunks = [] | |
}) | |
}) | |
}) | |
}) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment