-
Notifications
You must be signed in to change notification settings - Fork 64
/
demo.js
39 lines (31 loc) · 1.14 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// Copyright (c) 2018 Alexandre Storelli
const childProcess = require('child_process');
// const { Codegen } = require('stream-audio-fingerprint');
// Swap the line above if you're running this outside of the repo
const { Codegen } = require('./lib');
const decoder = childProcess.spawn('ffmpeg', [
'-i', 'pipe:0',
'-acodec', 'pcm_s16le',
'-ar', '22050',
'-ac', '1',
'-f', 'wav',
'-v', 'fatal',
'pipe:1'
], { stdio: ['pipe', 'pipe', process.stderr] });
const fingerprinter = new Codegen();
// Pipe ouput of ffmpeg decoder to fingerprinter
decoder.stdout.pipe(fingerprinter);
// Pipe input to this file to ffmpeg decoder
process.stdin.pipe(decoder.stdin);
// Log all the found fingerprints as they come in
fingerprinter.on('data', data => {
for (let i = 0; i < data.tcodes.length; i++) {
console.log(`time=${data.tcodes[i]} fingerprint=${data.hcodes[i]}`);
}
});
fingerprinter.on('end', () => {
console.log('Fingerprints stream ended.');
});