Created
November 4, 2017 18:29
-
-
Save ipiyer/286f18e629303510bd83fc8572f6c560 to your computer and use it in GitHub Desktop.
calculate pcm audio length
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { Transform } = require("readable-stream"); | |
| const fs = require('fs'); | |
| class PCMTime extends Transform { | |
| constructor() { | |
| super(); | |
| this.length = 0; | |
| // bitsPerSample * samplesPerSecond * channels | |
| this.bytesPerSec = (16 * 44100 * 1) / 8; | |
| } | |
| _transform(chunk, env, cb) { | |
| this.length += chunk.length; | |
| cb(null, chunk); | |
| } | |
| end() { | |
| console.log("pcm audio length:", this.bytesPerSec / this.length); | |
| } | |
| } | |
| var test = fs | |
| .createReadStream("asdf_in.pcm") | |
| .pipe(new PCMTime) | |
| .pipe(fs.createWriteStream('test.pcm')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment