1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.js で曲を奏でる

Posted at

ネタ元: 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

かっこいい

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?