forked from tonistiigi/audiosprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
131 lines (120 loc) · 3.13 KB
/
cli.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env node
var fs = require('fs')
var _ = require('underscore')._
var winston = require('winston')
var audiosprite = require('./audiosprite')
var optimist = require('optimist')
.options('output', {
alias: 'o'
, 'default': 'output'
, describe: 'Name for the output files.'
})
.options('path', {
alias: 'u'
, 'default': ''
, describe: 'Path for files to be used on final JSON.'
})
.options('export', {
alias: 'e'
, 'default': 'ogg,m4a,mp3,ac3'
, describe: 'Limit exported file types. Comma separated extension list.'
})
.options('format', {
alias: 'f'
, 'default': 'jukebox'
, describe: 'Format of the output JSON file (jukebox, howler, createjs).'
})
.options('log', {
alias: 'l'
, 'default': 'info'
, describe: 'Log level (debug, info, notice, warning, error).'
})
.options('autoplay', {
alias: 'a'
, 'default': null
, describe: 'Autoplay sprite name.'
})
.options('loop', {
'default': null
, describe: 'Loop sprite name, can be passed multiple times.'
})
.options('silence', {
alias: 's'
, 'default': 0
, describe: 'Add special "silence" track with specified duration.'
})
.options('gap', {
alias: 'g'
, 'default': 1
, describe: 'Silence gap between sounds (in seconds).'
})
.options('minlength', {
alias: 'm'
, 'default': 0
, describe: 'Minimum sound duration (in seconds).'
})
.options('bitrate', {
alias: 'b'
, 'default': 128
, describe: 'Bit rate. Works for: ac3, mp3, mp4, m4a, ogg.'
})
.options('vbr', {
alias: 'v'
, 'default': -1
, describe: 'VBR [0-9]. Works for: mp3. -1 disables VBR.'
})
.options('samplerate', {
alias: 'r'
, 'default': 44100
, describe: 'Sample rate.'
})
.options('channels', {
alias: 'c'
, 'default': 1
, describe: 'Number of channels (1=mono, 2=stereo).'
})
.options('rawparts', {
alias: 'p'
, 'default': ''
, describe: 'Include raw slices(for Web Audio API) in specified formats.'
})
.options('help', {
alias: 'h'
, describe: 'Show this help message.'
})
var argv = optimist.argv
var opts = _.extend({}, argv)
winston.remove(winston.transports.Console)
winston.add(winston.transports.Console, {
colorize: true
, level: argv.log
, handleExceptions: false
})
winston.debug('Parsed arguments', argv)
opts.logger = winston
opts.bitrate = parseInt(argv.bitrate, 10)
opts.samplerate = parseInt(argv.samplerate, 10)
opts.channels = parseInt(argv.channels, 10)
opts.gap = parseFloat(argv.gap)
opts.minlength = parseFloat(argv.minlength)
opts.vbr = parseInt(argv.vbr, 10)
opts.loop = argv.loop ? [].concat(argv.loop) : []
var files = _.uniq(argv._)
if (argv.help || !files.length) {
if (!argv.help) {
winston.error('No input files specified.')
}
winston.info('Usage: audiosprite [options] file1.mp3 file2.mp3 *.wav')
winston.info(optimist.help())
process.exit(1)
}
audiosprite(files, opts, function(err, obj) {
if (err) {
winston.error(err)
process.exit(0)
}
var jsonfile = opts.output + '.json'
fs.writeFileSync(jsonfile, JSON.stringify(obj, null, 2))
winston.info('Exported json OK', { file: jsonfile })
winston.info('All done')
})