ネタ元: countercomplex: Algorithmic symphonies from one line of code -- how and why?
Mac の場合 SoX をインストールする必要がある。
brew install sox
以下のコードを用意する
music.js
const { Readable } = require("stream");
class AudioReadable extends Readable {
constructor(options) {
super(options);
this.t = 0;
}
_read() {
this.t++;
const t = this.t;
const v = t * ((t>>12|t>>8)&63&t>>4);
this.push(Buffer.alloc(2, v));
}
}
new AudioReadable().pipe(process.stdout);
そして実行
node music.js | sox -traw -r 8k -c 1 -e unsigned-integer -b 16 - -d
かっこいい