Step 1

Make a directory inside your "tessel-code" folder: enter mkdir audio into your command line, then change directory into that folder: cd audio

Step 2

Plug in headphones or a speaker to the Headphones/Line out jack on your module. (You can also plug in a microphone to Line in, or just use the Mic built into the module.)

Step 3

Plug the audio module into Tessel port A with the hexagon/icon side down and the electrical components on the top, then plug Tessel into your computer via USB.

Step 4

Install by typing npm install audio-vs1053b into the command line.

Step 5

Save this code in a text file called audio.js:

// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/

/*********************************************
This Audio Module demo will record audio through
the mic while the CONFIG button is held down.
When the CONFIG button is released, the recorded
audio will be played back through the audio
out jack.
*********************************************/

var tessel = require('tessel');
var audio = require('audio-vs1053b').use(tessel.port['A']);

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;
});

Step 6

Locate the config button on Tessel. You'll be holding down this button to record sound.

Step 7

In your command line, tessel run audio.js
When prompted, hold down the config button and speak loudly at the Audio module. When you release the button the recording will be played back to you.

Bonus: Change the code so that recording stops automatically after 5 seconds.

To see what else you can do with the audio module, see the module docs here.

Step 8

What else can you do with a audio module? Try a community-created project.


What are you making? Share your invention!

If you run into any issues you can check out the audio forums.

Choose another module

Or if you're all set, move on to Wifi.

Fork on Github