0.4.0 • Published 6 years ago

@ismay/synesthesia v0.4.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

synesthesia

build status coverage status greenkeeper

convert between images, audio and text

This tool allows you to convert between .png files, .wav files and .txt files, in any direction. It uses a Uint32Array as an intermediary data structure. You can use this library from the command line with synesthesia-cli.

Installation

npm install -g @ismay/synesthesia

Example

So for example, to convert an image to sound:

const fs = require('fs');
const { fromImage, toWav } = require('@ismay/synesthesia');

fromImage(fs.readFileSync('image.png'))
  .then(uint32 => toWav(uint32))
  .then(outputWavBuffer => {
    fs.writeFileSync('sounds.wav');
  });

Usage

fromImage(imageBuffer) ⇒ Promise

Converts a 24 bit png image to a Uint32Array

Kind: global function Returns: Promise - Resolves to a Uint32Array

ParamTypeDescription
imageBufferBufferBuffer of the png image to convert

fromWav(wavBuffer) ⇒ Promise

Converts a 32 bit, mono wav to a Uint32Array

Kind: global function Returns: Promise - Resolves to a Uint32Array

ParamTypeDescription
wavBufferBufferBuffer of the wav to convert

fromText(textBuffer) ⇒ Promise

Converts text to a Uint32Array

Kind: global function Returns: Promise - Resolves to a Uint32Array

ParamTypeDescription
textBufferBufferBuffer of the text file to convert

toImage(quadlets, options) ⇒ Promise

Converts a Uint32Array to a 24 bit png image

Kind: global function Returns: Promise - Resolves to a 24 bit png image buffer

ParamTypeDescription
quadletsUint32ArrayArray of values to convert
optionsObject
options.widthnumberWidth of the rendered image in pixels
options.heightnumberHeight of the rendered image in pixels

toWav(quadlets, options) ⇒ Promise

Converts a Uint32Array to a 32 bit, mono wav

Kind: global function Returns: Promise - Resolves to a 32 bit, mono wav buffer

ParamTypeDefaultDescription
quadletsUint32ArrayArray of values to convert
optionsObject
options.sampleRatenumber44100Samplerate of the rendered wav

toText(quadlets) ⇒ Promise

Converts a Uint32Array to text

Kind: global function Returns: Promise - Resolves to a text file buffer

ParamTypeDescription
quadletsUint32ArrayArray of values to convert

License

MIT