piano-notes-ts
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

piano-notes-ts

TypeScript library for playing high-quality, public-domain piano note samples. Forked from Chris Wilson's Piano-Notes library.

Usage

Install from NPM

npm install piano-notes-ts

Then import Notes and whichever audio samples you want:

import { Notes } from '../piano-notes-ts'
import { Piano_500 } from '../piano-notes-ts' 	// 500ms samples, ~1MB
import { Piano_1000 } from '../piano-notes-ts'	// 1-second samples, ~2MB
import { Piano_2000 } from '../piano-notes-ts'	// 2-second samples, ~4MB

let notes = new Notes();

Then, for whichever of the samples you've imported, load them into the notes instance:

notes.loadAudio([ Piano_500, Piano_1000 ]); // can load either one sample or multiple in an array

Then play the notes at your leisure:

notes.A4.play(500)
notes.Bb5.play()	// defaults to 1000ms

Samples

All the samples are loaded as base64 strings in Piano_500, etc., so that you don't have to download a bunch of mp3 files and locate them. The following describes the process for generating these files in case you want to add more samples, but isn't something you need to run otherwise.

Source

The University of Iowa Electronic Music Studios has generously provided free, high-quality .aiff files of all 88 notes on a Steinway & Sons Model B. These were downloaded using the ./samples/download.sh script, but you don't need to do this unless you want to format them differently than I have.

Conversion

We want mp3 files for maximum browser compatibility and file size. The original sample have a small amount of silence in the beginning that needs to be cut, and they need to be reduced to 1 seconds. This StackOverflow has useful advice on how to do this with ffmpeg:

ffmpeg -i ./samples/original/Piano.ff.C4.aiff -af loudnorm,silenceremove=start_periods=1:start_silence=0:start_threshold=-40dB,afade=out:st=0.25:d=0.25 -to 0.5 ./samples/test.mp3

You can format them all with ./samples/format.sh. This will create three samples for each of the 88 notes: a 500ms, 1-second and 2-second version, all mp3s.

Biniaries

To avoid any lag or complicated paths to the modules, each duration of samples are converted to base64 and wrapped into a JSON file to be imported. To do so--again, you don't have to do this unless you're rebuilding--one runs the Node module convertNotes.js in the code directory.

This produces three files in the data/audio directory: audio_500.json, audio_1000.json and audio_2000.json. At present, they're 1MB, 2MB and 3.9 MB respectively.

Readme

Keywords

Package Sidebar

Install

npm i piano-notes-ts

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

13.7 MB

Total Files

44

Last publish

Collaborators

  • gregowen