Tessel Audio
Decode audio files or streams and output; record audio.
Make your Tessel play a tune, or listen in…
- Decodes MP3/AAC/WMA/MIDI/FLAC/Ogg Vorbis files
- Supports files and streams
- Supports both headphones and line-out
- Can record audio through an on-board microphone or line-in jack
For more info visit here.
How To Connect
Cylon.robot({ connections: { tessel: { adaptor: 'tessel' }, tessel_A: { adaptor: 'tessel', port: 'A' }, }, devices: { button: { driver: 'button', connection: 'tessel' }, audio: { driver: 'audio-vs1053b', connection: 'tessel_A' }, }, });
How To Use
var Cylon = require('cylon'); Cylon.robot({ connections: { tessel: { adaptor: 'tessel' }, tessel_A: { adaptor: 'tessel', port: 'A' }, }, devices: { button: { driver: 'button', 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) }); // When we get data, push it into our array my.audio.on('data', function(data) { chunks.push(data); }); console.log('Hold the config button to record...'); my.button.on('push', function() { // Tell the audio module to start recording if (!recording) { my.audio.startRecording('voice', function(err) { if (err) { console.log("Error while startRecording: ", err); } console.log('Recording...'); recording = true; }); } }); // Once the button is released, stop recording my.button.on('release', function() { // Tell the audio module to stop recording 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...'); // Concat the data and play it my.audio.play(Buffer.concat(chunks), function(err) { if (err) { console.log("Error during playback: ", err); } // When we're done playing, clear recordings chunks = []; console.log('Hold the config button to record...'); }); }); }); } }).start();
Commands
audio.setVolume( leftChannelDb, [rightChannelDb,] callback(err) )
Set the output volume. Level is a Number from 0.0 to 1.0
audio.setInput( input, callback(err) )
Set the input to either 'lineIn' or 'mic'. Defaults to 'lineIn'.
audio.setOutput( output, callback(err) )
Set the output to either 'lineOut' or 'headPhones'. Defaults to 'lineOut'.
audio.startRecording( [profile] callback(err) )
Start recording sound from the input. (Receive data in the 'data' event) Callback called after recording initialized (not stopped ) .quality is an optional argument that can be 'voice', 'wideband-voice', 'wideband-stereo', 'hifi-voice', or 'stereo-music'. Default is 'hifi-voice'.
audio.stopRecording( callback(err) )
Stop recording sound (note that may receive one more 'data' event before this completes when the buffer is flushed. )
audio.play( [audioBuff], callback(err) )
Play a buffer. If no buffer is passed in, the module will attempt to resume a buffer that was paused.
audio.pause( callback(err) )
Pause the buffer.
audio.stop( callback(err) )
Stop playing and flush the buffer.
audio.createPlayStream()
Returns a stream that a buffer can be piped into to play audio.
audio.createRecordStream()
Returns a readable stream of mic data.
audio.availableRecordingProfiles()
Returns an array of available profiles.
Events
'ready'
The audio module is ready to use.
'error'
The audio module had an error on connection.
'volume'
Volume was set.
'input'
The input mode was set.
'output'
The output mode was set.
'startRecording'
Started recording from the input.
'data'
Received recorded data.
'stopRecording'
Stopped recording on the input.
'play'
A buffer is beginning to be played.
'pause'
Playback was paused.
'stop'
Playback was stopped.
'end'
The buffer finished playing.