@ismay/synesthesia v0.4.0
synesthesia
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
Param | Type | Description |
---|---|---|
imageBuffer | Buffer | Buffer 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
Param | Type | Description |
---|---|---|
wavBuffer | Buffer | Buffer of the wav to convert |
fromText(textBuffer) ⇒ Promise
Converts text to a Uint32Array
Kind: global function Returns: Promise - Resolves to a Uint32Array
Param | Type | Description |
---|---|---|
textBuffer | Buffer | Buffer 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
Param | Type | Description |
---|---|---|
quadlets | Uint32Array | Array of values to convert |
options | Object | |
options.width | number | Width of the rendered image in pixels |
options.height | number | Height 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
Param | Type | Default | Description |
---|---|---|---|
quadlets | Uint32Array | Array of values to convert | |
options | Object | ||
options.sampleRate | number | 44100 | Samplerate of the rendered wav |
toText(quadlets) ⇒ Promise
Converts a Uint32Array to text
Kind: global function Returns: Promise - Resolves to a text file buffer
Param | Type | Description |
---|---|---|
quadlets | Uint32Array | Array of values to convert |