[UNMAINTAINED] JavaScript module for the VS1053b audio driver.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
plugins
test
.gitignore
COPYRIGHT
LICENSE-APACHE
LICENSE-MIT
README.md
index.js
package.json
sample.mp3

README.md

[UNMAINTAINED] This library does not have a maintainer. The source code and repository will be kept at this URL indefinitely. If you'd like to help maintain this codebase, create an issue on this repo explaining why you'd like to become a maintainer and tag @tessel/maintainers in the body.

#Audio Driver for the audio-vs1053b Tessel audio module. The hardware documentation for this module can be found here.

  • 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

If you run into any issues you can ask for support on the Audio Module Forums.

###Installation

npm install audio-vs1053b

###Limitations The current version of the Tessel runtime is too slow to play audio files smoothly. That means we wrote a custom C shim that handles most of the playback and recording of data. There are several consequences of the C shim:

  • Any other modules that use SPI for communication will be blocked while the Audio Module is playing a buffer.
  • You can only have one Audio Module attached to Tessel at a time.
  • Updates to the Audio Module driver must be released in both firmware and this npm repo.

It sucks but we're expecting major runtime speed improvements to render the C shim unnecessary within the next couple of months.

###Development Status Playback and recording to/from the local file system works well. Streams work less well. Interacting with the SDCard, Ambient, and IR doesn't work yet (issues with the SPI bus). This module is currently undergoing heavy development to fix those issues. Please file any bugs you find with this module.

###Example

/*********************************************
This Audio Module demo sets volume, then plays
an audio file out over Headphones/Line out
*********************************************/

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

var audioFile = 'sample.mp3';

// Wait for the module to connect
audio.on('ready', function() {
  console.log("Audio module connected! Setting volume...");
  // Set the volume in decibels. Around .8 is good; 80% max volume or -25db
  audio.setVolume(.8, function(err) {
    if (err) {
      return console.log(err);
    }
    // Get the song
    console.log('Retrieving file...');
    var song = fs.readFileSync(audioFile);
    // Play the song
    console.log('Playing ' + audioFile + '...');
    audio.play(song, function(err) {
      if (err) {
        console.log(err);
      } else {
        console.log('Done playing', audioFile);
      }
    });
  });
});

// If there is an error, report it
audio.on('error', function(err) {
  console.log(err);
});

###Methods

# audio.setVolume( leftChannelDb, [rightChannelDb,] callback(err) )
Set the output volume. Level is a Number from 0.0 to 1.0 (-127dB to 0dB)

# audio.setInput( input, callback(err) )
Set the input to either 'lineIn' or 'mic'. Defaults to 'mic'.

# audio.setOutput( output, callback(err) )
Set the output to either 'lineOut' or 'headphones'. Defaults to 'headphones'.

# 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

# audio.on( 'ready', callback() )
The audio module is ready to use.

# audio.on( 'error', callback(err) )
The audio module had an error on connection.

# audio.on( 'volume', callback(volume) )
Volume was set.

# audio.on( 'input', callback(input) )
The input mode was set.

# audio.on( 'output', callback(output) )
The output mode was set.

# audio.on( 'startRecording', callback() )
Started recording from the input.

# audio.on( 'data', callback(audioBuff) )
Received recorded data.

# audio.on( 'stopRecording', callback() )
Stopped recording on the input.

# audio.on( play', callback() )
A buffer is beginning to be played.

# audio.on( 'pause', callback() )
Playback was paused.

# audio.on( 'stop', callback() )
Playback was stopped.

# audio.on( 'end', callback(err) )
The buffer finished playing.

###Further Examples

  • Audio Out No Streams. This Audio Module demo sends audio from a file to Headphones/Line out without using streams..
  • Record Sound. This Audio Module demo sends audio from the microphone to a file without using streams.
  • Stream Audio Out. This Audio Module demo sends audio from a file to Headphones/Line out using streams.
  • Stream Sound to File. This Audio Module demo takes line-in and writes it to a file using streams.

###License MIT or Apache 2.0, at your option