"use strict";
var Cylon = require("cylon");
Cylon.robot({
connections: {
tessel: { adaptor: "tessel" },
tessel_A: { adaptor: "tessel", port: "A" },
},
devices: {
button: { driver: "button", pin: "config", connection: "tessel" },
audio: { driver: "audio-vs1053b", connection: "tessel_A" },
},
work: function(my) {
var chunks = [];
var recording = false;
my.audio.on("error", function(err) {
console.log(err);
});
my.audio.on("data", function(data) {
chunks.push(data);
});
console.log("Hold the config button to record...");
my.button.on("push", function() {
if (!recording) {
my.audio.startRecording("voice", function(err) {
if (err) {
console.log("Error while startRecording: ", err);
}
console.log("Recording...");
recording = true;
});
}
});
my.button.on("release", function() {
console.log("stopping the recording...");
recording = false;
my.audio.stopRecording(function(err) {
if (err) {
console.log("Error while stopRecording: ", err);
}
console.log("Playing it back...");
my.audio.play(Buffer.concat(chunks), function(error) {
if (error) {
console.log("Error during playback: ", error);
}
chunks = [];
console.log("Hold the config button to record...");
});
});
});
}
}).start();