-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·64 lines (57 loc) · 1.33 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env node
import { walk } from './lib/walk.js';
import { detectSilence } from './lib/detect-silince.js';
import { splitOnSilence } from './lib/split-on-silence.js';
import { confirmSplit } from './lib/confirm-split.js';
const defaultPattern = /.\.(?:mp3|ogg|m4a|aac|flac)$/i;
async function main()
{
const pattern = (
process.env['SPLIT_ON_SILENCE_PATTERN']
? new RegExp( process.env['SPLIT_ON_SILENCE_PATTERN'], 'i' )
: defaultPattern
);
const duration = process.env['SPLIT_ON_SILENCE_DURATION'] || 10;
const noise = process.env['SPLIT_ON_SILENCE_NOISE'] || '-60dB';
for await ( const path of walk( process.cwd(), pattern ) )
{
try
{
const {
silenceSegments,
totalDuration,
} = await detectSilence( path, duration, noise );
if (
( silenceSegments.length !== 0 )
&& await confirmSplit( path, totalDuration, silenceSegments )
)
{
const outputLines = await splitOnSilence( path, silenceSegments );
console.log( outputLines.join( '\n' ) );
}
}
catch ( error )
{
if (
( typeof error === 'object' )
&& ( error !== null )
&& ( 'stderr' in error )
)
{
console.error( error.stderr );
}
else
{
console.error( 'Can\'t process file', path );
}
}
}
}
main()
.catch(
( error ) =>
{
console.error( error );
process.exit( 1 );
},
);