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

troubadour

v0.0.5

Published

Node.js Audio Player

Downloads

7

Readme

Troubadour

Build Status NPM

Troubadour is wrapper over command-line audio players that makes it easy to play audio in Node.js. At this point, the following audio players are supported:

  • mpg123
  • MPlayer
  • SoX
  • VLC

Other audio players can easily be added by adding entries into the supportedAudioPlayers.json file.

Installation

npm install troubadour

Since Troubadour uses command-line audio players to facilitate audio playback, you will also need to install one of the supported players.

Usage

Getting Started

To get started, require the module in your program and create a new Troubadour instance by passing the name of the supported audio player into the constructor.

const Troubadour = require('troubadour');
const troubadour = new Troubadour('sox');

Troubadour is an event emitter that indicates when certain actions are being performed by the audio player. The following code snippet shows how to add an event listener to your new troubadour player.

troubadour.on('eventname', () => {
  // Event listener function
});

You do not need to have listeners set up in order to use Troubadour but they provide a programmatic way of defining actions that you would like to take when the audio playback starts, pauses, stops, resumes, ends, and errors.

Play

To play an audio source, use the play function and pass in the file path of the audio source that is to be played:

troubadour.on('start', () => {
  // Do something here when the audio starts playing
});

troubadour.on('end', () => {
  // Do something here when the audio finishes playing
});

troubadour.play('~/Music/audiofile.mp3');

Pause

Pause the playback (with the ability to resume later) by using the pause function:

troubadour.on('pause', () => {
  // Do something here when the audio is paused
});

troubadour.pause();

Stop

Stop the playback (without the ability to resume later) by using the stop function:

troubadour.on('stop', () => {
  // Do something here when the audio is stopped
});

troubadour.stop();

Resume

Resume the playback from a paused state by using the resume function:

troubadour.on('resume', () => {
  // Do something here when the audio is resumed
});

troubadour.resume();

Errors

Troubadour handles errors in two different ways: abruptly throwing an error when the error is not recoverable or gracefully emitting the error when it is recoverable.

Errors like not passing the name of a supported command-line audio player to the Troubadour constructor are not recoverable, so the module will throw an error. Errors like calling the play function without specifying a file path are recoverable, so Troubadour will just emit an error event to let the user know.

The error listener can be set up by including the following:

troubadour.on('error', (error) => {
  // Do something here to handle the errors
});

The error parameter in the callback listener function is an error object. Just like any error object, accessing the error message can be done through error.message.