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

lambda-audio

v1.0.0

Published

Run Sound eXchange (SoX), the Swiss Army knife of audio manipulation, with Lame on AWS Lambda.

Downloads

21

Readme

SoX for AWS Lambda

Run Sound eXchange (SoX), the Swiss Army knife of audio manipulation, with Lame on AWS Lambda.

What

lambda-audio is static binary of sox utility, built for AWS Lambda. It supports sox, soxi and lame commands.

Why

lambda-audio allows you to covert and merge multiple audio files using AWS Lambda.

You can use it as a replacement/cheaper version of Amazon Elastic Transcoder. Or you can use it for the workflows that are not currently possible on Elastic Transcoder.

Motivation behind this library was a use case where we had up to five audio file that needs to be merged with specific rules — we need to put music in the background and different pauses between voice files. Service is used only from time to time, but we had instance for node.js app running all the time. This library is trying to solve that problem and allow us to do merging and conversion in AWS Lambda.

How

Installation

You can install this package from NPM by running following command:

npm install lambda-audio --save

Usage

After you require node module in your code by adding:

const lambdaAudio = require('lambda-audio')

lambdaAudio will contain three functions:

  • sox
  • soxi
  • lame

Each of the functions receives 1 argument that can be the string that contains the command or an array of attributes that needs to be passed to the command.

Each function is returning promise that will resolve when the command is successfully executed or has an error. Success answers will go to .then statement, errors will go to .catch statement. Response for both success and error will be passed as a string argument.

See below for the examples.

sox command

Let's say that you want to convert input.mp3 file to mono, and output it as output.wav file, in command line you would do that like this:

sox input.mp3 -c 1 output.wav

With lambda-audio you can do that by passing the command as a string, just without sox part, like this:

lambdaAudio.sox('./input.mp3 -c 1 /tmp/output.wav')
  .then(response => {
    // Do something when the file was converted
  })
  .catch(errorResponse => {
    console.log('Error from the sox command:', errorResponse)
  })

Or by passing the arguments as an array:

lambdaAudio.sox(['./input.mp3', '-c', '1', '/tmp/output.wav'])
  .then(response => {
    // Do something when the file was converted
  })
  .catch(errorResponse => {
    console.log('Error from the sox command:', errorResponse)
  })

Keep in mind that AWS Lambda is read only and that the output path needs to be in /tmp folder.

For the full list of options, visit sox documentation.

soxi command

Let's say that you want to see the info about input.mp3 file, in command line you would do that like this:

soxi input.mp3

With lambda-audio you can do that by passing the command as a string:

lambdaAudio.soxi('./input.mp3')
  .then(response => {
    // Do something with the info
  })
  .catch(errorResponse => {
    console.log('Error from the soxi command:', errorResponse)
  })

Or by passing the arguments as an array:

lambdaAudio.soxi(['./input.mp3'])
  .then(response => {
    // Do something with the info
  })
  .catch(errorResponse => {
    console.log('Error from the soxi command:', errorResponse)
  })

For the full list of options, visit soxi documentation.

lame command

Let's say you want to re-encode existing MP3 to 64 kbps MP3, in command line you would do it like this:

lame -b 64 input.mp3 output.mp3

With lambda-audio you can do that by passing the command as a string:

lambdaAudio.lame('-b 64 ./input.mp3 /tmp/output.mp3')
  .then(response => {
    // Do something with the new mp3 file
  })
  .catch(errorResponse => {
    console.log('Error from the lame command:', errorResponse)
  })

Or by passing the arguments as an array:

lambdaAudio.lame(['-b', '64', './input.mp3', '/tmp/output.mp3'])
  .then(response => {
    // Do something with the new mp3 file
  })
  .catch(errorResponse => {
    console.log('Error from the lame command:', errorResponse)
  })

For the full list of options, visit lame documentation.

Deployment

lambda-audio is working perfectly with Claudia.js library, but you can use it with other AWS Libraries and frameworks too.

With Claudia.js, simply save lambda-audio as a dependency and then you can deploy your AWS Lambda function using standard claudia create command.

Testing

We use Jasmine for unit and integration tests. Unless there is a very compelling reason to use something different, please continue using Jasmine for tests. The existing tests are in the spec folder. Here are some useful command shortcuts:

Run all the tests:

npm test

Run only some tests:

npm test -- filter=prefix

Get detailed hierarchical test name reporting:

npm test -- full

License

GNU GENERAL PUBLIC LICENSE, Version 2 -- see LICENSE