npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

audio-vs1053b

v0.2.0

Published

Library to run the Tessel Audio Module. Plays and records sound.

Downloads

15

Readme

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

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 '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

# 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