audio_hero 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -1
- data/audio_hero.gemspec +2 -2
- data/lib/audio_hero/version.rb +1 -1
- data/lib/audio_hero.rb +61 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4bb1e0dddd042652fedc3c8afa209a38782599ad
|
4
|
+
data.tar.gz: e240c77cdc42674a5c16beb480714a5078315577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b04e7418655b10d21e43444104c3d4d0c8610d30022203cd95b7fc310ea7e0d7bba1b92a5267607dd32c8662987274ba59c5b9de69d97b2fa220fe85f9218338
|
7
|
+
data.tar.gz: 9fe578470e0bf6c95e6cc220a89e13b7615e277b87a6c107126f04be2b83e91ddf7a1c742e77c0f67f81f003187df3d3e73c1b1a33e65821997aa87ae12f9fb9
|
data/README.md
CHANGED
@@ -31,6 +31,8 @@ Or install it yourself as:
|
|
31
31
|
Return the converted audio as ruby temp file object
|
32
32
|
|
33
33
|
```ruby
|
34
|
+
require "open-uri"
|
35
|
+
|
34
36
|
file = open("url/or/path/to/audio/file")
|
35
37
|
|
36
38
|
new_file = AudioHero::Sox.new(file).convert({output_options: "-c 1", output_format: "mp3", channel: "left"})
|
@@ -73,12 +75,23 @@ Options(hash):
|
|
73
75
|
* file2 (path to second audio file, I use this to split both channels of an audio file at one go, require a modified sox that will not overwrite file1's output. Eg. my modified sox output [milliseconds].wav instead of 001.wav)
|
74
76
|
* gc (no default, set to "true" to auto close! input file)
|
75
77
|
|
78
|
+
###Stats
|
79
|
+
Get statistics report on audio file (support up to 2 channels).
|
80
|
+
|
81
|
+
```ruby
|
82
|
+
stats = AudioHero::Sox.new(file).stats({input_format: "wav"})
|
83
|
+
# {"dc_offset"=>"0.000398", "min_level"=>"-0.299591", "max_level"=>"0.303711", "pk_lev_db"=>"-10.35", "rms_lev_db"=>"-23.08", "rms_pk_db"=>"-16.19", "rms_tr_db"=>"-96.84", "crest_factor"=>"4.33", "flat_factor"=>"0.00", "pk_count"=>"2", "bit-depth"=>"15/16", "num_samples"=>"233k", "length_s"=>"14.544", "scale_max"=>"1.000000", "window_s"=>"0.050"}
|
84
|
+
```
|
85
|
+
Options(hash):
|
86
|
+
* input_format (default to "mp3")
|
87
|
+
* gc (no default, set to "true" to auto close! input file)
|
88
|
+
|
76
89
|
###Custom Command
|
77
90
|
|
78
91
|
Run any sox command with this method.
|
79
92
|
```ruby
|
80
93
|
file = AudioHero::Sox.new(file).command({global: "-V3", input_option: "-t mp3", output_option: "-c 1", effect: "remix 0 1", gc: "true"})
|
81
|
-
# Command generated:
|
94
|
+
# Command generated: sox -V3 -t mp3 input.mp3 -c 1 output.wav remix 0 1
|
82
95
|
```
|
83
96
|
Options(hash):
|
84
97
|
* global (sox global options, inserted right after `sox`)
|
data/audio_hero.gemspec
CHANGED
@@ -7,10 +7,10 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "audio_hero"
|
8
8
|
spec.version = AudioHero::VERSION
|
9
9
|
spec.authors = ["litenup"]
|
10
|
-
spec.email = ["alanhsu@
|
10
|
+
spec.email = ["alanhsu@mycallhero.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{Wrapper for sox for audio processing}
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "https://github.com/litenup/audio_hero"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
data/lib/audio_hero/version.rb
CHANGED
data/lib/audio_hero.rb
CHANGED
@@ -24,9 +24,9 @@ module AudioHero
|
|
24
24
|
output_options = options[:default] ? "-c 1 -b 16 -r 16k" : options[:output_options]
|
25
25
|
case channel
|
26
26
|
when "left"
|
27
|
-
channel = "remix 1
|
27
|
+
channel = "remix 1"
|
28
28
|
when "right"
|
29
|
-
channel = "remix
|
29
|
+
channel = "remix 2"
|
30
30
|
else
|
31
31
|
channel = nil
|
32
32
|
end
|
@@ -111,6 +111,24 @@ module AudioHero
|
|
111
111
|
Dir["#{dir}/**/*#{format}"]
|
112
112
|
end
|
113
113
|
|
114
|
+
def stats(options={})
|
115
|
+
input_format = options[:input_format] ? options[:input_format] : "mp3"
|
116
|
+
src = @file
|
117
|
+
begin
|
118
|
+
parameters = []
|
119
|
+
parameters << "-t #{input_format}"
|
120
|
+
parameters << ":source"
|
121
|
+
parameters << "-n stats"
|
122
|
+
parameters << "2>&1" # redirect stderr to stdout
|
123
|
+
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
124
|
+
success = Cocaine::CommandLine.new("sox", parameters).run(:source => File.expand_path(src.path))
|
125
|
+
rescue => e
|
126
|
+
raise AudioHeroError, "These was an issue getting stats from #{@basename}"
|
127
|
+
end
|
128
|
+
src.close! if options[:gc] == "true"
|
129
|
+
parse_stats(success)
|
130
|
+
end
|
131
|
+
|
114
132
|
def command(options={})
|
115
133
|
global = options[:global_options]
|
116
134
|
input_options = options[:input_options]
|
@@ -140,6 +158,47 @@ module AudioHero
|
|
140
158
|
dst
|
141
159
|
end
|
142
160
|
|
161
|
+
private
|
162
|
+
|
163
|
+
def parse_stats(stats)
|
164
|
+
hash = Hash.new { |h, k| h[k] = {} }
|
165
|
+
if stats.include? "Left"
|
166
|
+
stats.split("\n").drop(1).each do |row|
|
167
|
+
overall = hash[:overall]
|
168
|
+
left = hash[:left]
|
169
|
+
right = hash[:right]
|
170
|
+
array = row.split(" ")
|
171
|
+
if array.count == 4
|
172
|
+
label = array[0].downcase!
|
173
|
+
overall[label] = array[1]
|
174
|
+
left[label] = array[2]
|
175
|
+
right[label] = array[3]
|
176
|
+
elsif array.count > 4
|
177
|
+
label = array.first(array.count - 3).join(" ").gsub!(/( )/, '_').downcase!
|
178
|
+
values = array.last(3)
|
179
|
+
overall[label] = values[0]
|
180
|
+
left[label] = values[1]
|
181
|
+
right[label] = values[2]
|
182
|
+
else
|
183
|
+
label = array.first(array.count - 1).join(" ").gsub!(/( )/, '_').downcase!
|
184
|
+
overall[label] = array.last
|
185
|
+
left[label] = array.last
|
186
|
+
right[label] = array.last
|
187
|
+
end
|
188
|
+
end
|
189
|
+
else
|
190
|
+
stats.split("\n").each do |row|
|
191
|
+
array = row.split(" ")
|
192
|
+
if array.count == 2
|
193
|
+
hash[array.first.downcase!] = array.last
|
194
|
+
elsif array.count > 2
|
195
|
+
hash[array.first(array.count - 1).join(" ").gsub!(/( )/, '_').downcase!] = array.last
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
hash
|
200
|
+
end
|
201
|
+
|
143
202
|
end
|
144
203
|
end
|
145
204
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: audio_hero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- litenup
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,7 +68,7 @@ dependencies:
|
|
68
68
|
version: '0.5'
|
69
69
|
description:
|
70
70
|
email:
|
71
|
-
- alanhsu@
|
71
|
+
- alanhsu@mycallhero.com
|
72
72
|
executables: []
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
@@ -86,7 +86,7 @@ files:
|
|
86
86
|
- bin/setup
|
87
87
|
- lib/audio_hero.rb
|
88
88
|
- lib/audio_hero/version.rb
|
89
|
-
homepage:
|
89
|
+
homepage: https://github.com/litenup/audio_hero
|
90
90
|
licenses:
|
91
91
|
- MIT
|
92
92
|
metadata:
|