-
Notifications
You must be signed in to change notification settings - Fork 53
/
waveform
executable file
·67 lines (55 loc) · 2.19 KB
/
waveform
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
#!/usr/bin/env ruby
require "waveform"
require "optparse"
options = Waveform::DefaultOptions
optparse = OptionParser.new do |o|
o.banner = "Usage: waveform [options] source_audio [output.png]"
o.version = Waveform::VERSION
o.on("-W", "--width WIDTH", "Width (in pixels) of generated waveform image -- Default #{Waveform::DefaultOptions[:width]}.") do |width|
options[:width] = width.to_i
end
o.on("-H", "--height HEIGHT", "Height (in pixels) of generated waveform image -- Default #{Waveform::DefaultOptions[:height]}.") do |height|
options[:height] = height.to_i
end
o.on("-a", "--autowidth MSEC", "Sets the width of the waveform based on the audio length, using a resolution of the given msec per pixel.") do |msec|
options[:auto_width] = msec.to_i
end
o.on("-c", "--color COLOR", "Color (hex code) to draw the waveform. Can also pass 'transparent' to cut it out of the background -- Default #{Waveform::DefaultOptions[:color]}.") do |color|
if color == "transparent"
options[:color] = :transparent
else
options[:color] = color.match(/#.*/) ? color : "##{color}"
end
end
o.on("-b", "--background COLOR", "Background color (hex code) to draw waveform on -- Default #{Waveform::DefaultOptions[:background_color]}.") do |color|
if color == "transparent"
options[:background_color] = :transparent
else
options[:background_color] = color.match(/#.*/) ? color : "##{color}"
end
end
o.on("-m", "--method METHOD", "Wave analyzation method (can be 'peak' or 'rms') -- Default '#{Waveform::DefaultOptions[:method]}'.") do |method|
options[:method] = method.to_sym
end
options[:logger] = $stdout
o.on("-q", "--quiet", "Don't print anything out when generating waveform") do
options[:logger] = nil
end
options[:force] = false
o.on("-F", "--force", "Force generation of waveform if file exists") do
options[:force] = true
end
o.on("-h", "--help", "Display this screen") do
puts o
exit
end
end
optparse.parse!
begin
Waveform.generate(ARGV[0], ARGV[1] || "waveform.png", options)
rescue Waveform::ArgumentError => e
puts e.message + "\n\n"
puts optparse
rescue Waveform::RuntimeError => e
puts e.message
end