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

soundtouchjs

v0.1.30

Published

An ES2015 library for manipulating Web Audio Contexts

Downloads

4,315

Readme

SoundTouchJS

[Note]: Check out the AudioWorklet implementation of SoundTouchJS

SoundTouchJS is an ES2015 library of audio context utilities, converted, expanded, and maintained by Cutter. Read the backstory. To see it in action:

Edit SoundTouchJS with React

Or, clone the repo and Run The Example.

Installation

You can easily install SoundTouchJS for use in your project:

npm install soundtouchjs

General Usage

You can use whatever method you prefer to get your audio file, but once you have the data you must decode it into an AudioBuffer. Once you've decoded the data you can then create a new PitchShifter.

import { PitchShifter } from 'soundtouchjs';

const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
const gainNode = audioCtx.createGain();
let shifter;

// here you retrieved your file with 'fetch' or a new instance of the 'FileReader', and from the data...
if (shifter) {
  shifter.off(); // remove any current listeners
}
audioCtx.decodeAudioData(buffer, (audioBuffer) => {
  shifter = new PitchShifter(audioCtx, audioBuffer, 1024);
  shifter.on('play', (detail) => {
    // do something with detail.timePlayed;
    // do something with detail.formattedTimePlayed;
    // do something with detail.percentagePlayed
  });
  shifter.tempo = 1;
  shifter.pitch = 1;
});

To begin playback you connect the PitchShifter to the WebAudio destination (or another node), and disconnect it to pause. It's important to note that the PitchShifter is a pseudo-node, and cannot be connected to.

const play = function () {
  shifter.connect(gainNode); // connect it to a GainNode to control the volume
  gainNode.connect(audioCtx.destination); // attach the GainNode to the 'destination' to begin playback
};

Running The Example

An example has been included with the package to see some basic functionality. Prior to running the example you must install all dependencies.

npm i

If you've cloned the library, you need to build the code.

npm run build

It has been written in pure javascript, but could easily be integrated with your favorite framework.

Note: Run the example in a modern browser, as it uses es2015 import syntax.

To run the example:

npm start

then open your browser to http://localhost:8080. A royalty free music file is included under Creative Commons License with this repository.

Music: "Actionable" from Bensound.com.

This is a limited use license, and we do not grant any permissions beyond theirs. Please refer to their licensing for further information.

All core components of the package are available as separate entities for more advanced audio manipulations. See the source code for greater understanding.

Creating Your Own Build

As long as you've installed all dependencies, you can run the build script to create your own local version of SoundTouchJS. This is good when contributing changes back to the project.

npm run build

Contributing

If you want to contribute, Hooray! Just fork the repo, do your work in a branch, then submit a Pull Request when you're done. Code? Documentation? More Examples? Go for it!

Or maybe you just like what's been done? I accept cash

TODO

  • audio worklets - (Thank You to Janick Delot for sponsoring this upcoming feature)

In Case You Are Interested

SoundTouchJS is based on the C++ implementation of Soundtouch by Olli Parviainen. The earliest implementation in JavaScript was written by Ryan Berdeen and later expanded by Jakub Faila. I have further expanded this library into a distributable package, refactored for es2015 development.

This package includes the getWebAudioNode utility written by Adrian Holovaty, as well as the user-friendly PitchShifter wrapper from Jakub Faila.

Contributors