audio_hero 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +5 -0
- data/lib/audio_hero/version.rb +1 -1
- data/lib/audio_hero.rb +55 -31
- metadata +2 -7
- data/audio_hero-0.1.0.gem +0 -0
- data/audio_hero-0.1.1.gem +0 -0
- data/audio_hero-0.1.2.gem +0 -0
- data/audio_hero-0.1.3.gem +0 -0
- data/audio_hero-0.1.4.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c70b8a3e6428d14a447828fce06ae77f5c8b890
|
4
|
+
data.tar.gz: c1c59b50519a00aec1336fbf45b4b7dc02d7c01c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1b8aa51c4dec053e0158fadee1525d08958fbf7350496f1ce49b06e1b636deaaa6595922224ecf54787ad6e209c407472d1b96ee9a93eef1093dd0f841f4311
|
7
|
+
data.tar.gz: fb5a777a713d610da244b54b976654a3f41c536b5c2fd75538c203156be1e9ab694021cfecdc9fcca92f8b193a1e8cd5998233a7525841d531881c9487221b37
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -39,6 +39,11 @@ new_file = AudioHero::Sox.new(file).convert({output_options: "-c 1", output_form
|
|
39
39
|
# Optional: Close the file after you are done for garbage collection.
|
40
40
|
new_file.close!
|
41
41
|
|
42
|
+
# AudioHero can also take a direct filepath string as input
|
43
|
+
|
44
|
+
file_path = open("url/or/path/to/audio/file").path # "/path/to/tempfile"
|
45
|
+
new_file = AudioHero::Sox.new(file_path).convert({output_options: "-c 1", output_format: "mp3", channel: "left"})
|
46
|
+
|
42
47
|
# With no options hash it will runs this command by default: `sox -t input.mp3 -c 1 -b 16 -r 16k out.wav`
|
43
48
|
AudioHero::Sox.new(file).convert
|
44
49
|
```
|
data/lib/audio_hero/version.rb
CHANGED
data/lib/audio_hero.rb
CHANGED
@@ -14,7 +14,7 @@ module AudioHero
|
|
14
14
|
|
15
15
|
def initialize(file, options={})
|
16
16
|
@file = file
|
17
|
-
@basename =
|
17
|
+
@basename = get_basename(file)
|
18
18
|
end
|
19
19
|
|
20
20
|
# Usage: file = AudioHero::Sox.new(file).convert({output_options: "-c 1 -b 16 -r 16k", output_format: "mp3", channel: "left"}); file.close
|
@@ -31,7 +31,7 @@ module AudioHero
|
|
31
31
|
else
|
32
32
|
channel = nil
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
# Default conversion to wav
|
36
36
|
dst = Tempfile.new(["out", ".#{output_format}"])
|
37
37
|
begin
|
@@ -42,11 +42,11 @@ module AudioHero
|
|
42
42
|
parameters << ":dest"
|
43
43
|
parameters << channel if channel
|
44
44
|
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
45
|
-
success = Cocaine::CommandLine.new("sox", parameters).run(:source =>
|
45
|
+
success = Cocaine::CommandLine.new("sox", parameters).run(:source => get_path(@file), :dest => get_path(dst))
|
46
46
|
rescue => e
|
47
47
|
raise AudioHeroError, "There was an error converting #{@basename} to #{output_format}"
|
48
48
|
end
|
49
|
-
|
49
|
+
garbage_collect(@file) if options[:gc] == "true"
|
50
50
|
dst
|
51
51
|
end
|
52
52
|
|
@@ -56,11 +56,8 @@ module AudioHero
|
|
56
56
|
silence_level = options[:silence_level] || "0.03"
|
57
57
|
effect = "silence 1 #{silence_duration} #{silence_level}% -1 #{silence_duration} #{silence_level}%"
|
58
58
|
input_format = options[:input_format] ? options[:input_format] : "mp3"
|
59
|
-
output_format = options[:output_format] ? options[:output_format] : "wav"
|
59
|
+
output_format = options[:output_format] ? options[:output_format] : "wav" # Default to wav
|
60
60
|
|
61
|
-
# Default to wav
|
62
|
-
src = @file
|
63
|
-
# Default conversion to wav
|
64
61
|
dst = Tempfile.new(["out", ".#{output_format}"])
|
65
62
|
begin
|
66
63
|
parameters = []
|
@@ -69,11 +66,11 @@ module AudioHero
|
|
69
66
|
parameters << ":dest"
|
70
67
|
parameters << effect
|
71
68
|
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
72
|
-
success = Cocaine::CommandLine.new("sox", parameters).run(:source =>
|
69
|
+
success = Cocaine::CommandLine.new("sox", parameters).run(:source => get_path(@file), :dest => get_path(dst))
|
73
70
|
rescue => e
|
74
71
|
raise AudioHeroError, "There was an error converting #{@basename} to #{output_format}"
|
75
72
|
end
|
76
|
-
|
73
|
+
garbage_collect(@file) if options[:gc] == "true"
|
77
74
|
dst
|
78
75
|
end
|
79
76
|
|
@@ -89,15 +86,11 @@ module AudioHero
|
|
89
86
|
input_format = options[:input_format] ? options[:input_format] : "mp3"
|
90
87
|
output_format = options[:output_format]
|
91
88
|
output_filename = options[:output_filename] || "out"
|
92
|
-
# file2 = options[:file2]
|
93
89
|
# Default to wav
|
94
90
|
dir = Dir.mktmpdir
|
95
91
|
format = output_format ? ".#{output_format}" : ".wav"
|
96
92
|
dst = "#{dir}/#{output_filename}#{format}"
|
97
93
|
|
98
|
-
src = @file
|
99
|
-
# src2 = file2 if file2
|
100
|
-
|
101
94
|
begin
|
102
95
|
parameters = []
|
103
96
|
parameters << "-t #{input_format}"
|
@@ -105,23 +98,17 @@ module AudioHero
|
|
105
98
|
parameters << ":dest"
|
106
99
|
parameters << effect
|
107
100
|
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
108
|
-
success = Cocaine::CommandLine.new("sox", parameters).run(:source =>
|
109
|
-
# success = Cocaine::CommandLine.new("sox", parameters).run(:source => File.expand_path(src2.path), :dest => dst) if src2
|
101
|
+
success = Cocaine::CommandLine.new("sox", parameters).run(:source => get_path(@file), :dest => dst)
|
110
102
|
rescue => e
|
111
103
|
raise AudioHeroError, "There was an error splitting #{@basename}"
|
112
104
|
end
|
113
|
-
|
114
|
-
if options[:gc] == "true"
|
115
|
-
src.close!
|
116
|
-
# src2.close! if src2
|
117
|
-
end
|
105
|
+
garbage_collect(@file) if options[:gc] == "true"
|
118
106
|
|
119
107
|
Dir["#{dir}/**/*#{format}"]
|
120
108
|
end
|
121
109
|
|
122
110
|
def stats(options={})
|
123
111
|
input_format = options[:input_format] ? options[:input_format] : "mp3"
|
124
|
-
src = @file
|
125
112
|
begin
|
126
113
|
parameters = []
|
127
114
|
parameters << "-t #{input_format}"
|
@@ -129,28 +116,27 @@ module AudioHero
|
|
129
116
|
parameters << "-n stats"
|
130
117
|
parameters << "2>&1" # redirect stderr to stdout
|
131
118
|
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
132
|
-
success = Cocaine::CommandLine.new("sox", parameters).run(:source =>
|
119
|
+
success = Cocaine::CommandLine.new("sox", parameters).run(:source => get_path(@file))
|
133
120
|
rescue => e
|
134
121
|
raise AudioHeroError, "These was an issue getting stats from #{@basename}"
|
135
122
|
end
|
136
|
-
|
123
|
+
garbage_collect(@file) if options[:gc] == "true"
|
137
124
|
parse_stats(success)
|
138
125
|
end
|
139
126
|
|
140
127
|
# Requires custom version of yaafe
|
141
128
|
def extract_features(options={})
|
142
|
-
src = @file
|
143
129
|
rate = options[:sample_rate] || "8000"
|
144
130
|
begin
|
145
131
|
parameters = []
|
146
132
|
parameters << "-r #{rate}"
|
147
133
|
parameters << ":source"
|
148
134
|
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
149
|
-
success = Cocaine::CommandLine.new("yaafehero", parameters).run(:source =>
|
135
|
+
success = Cocaine::CommandLine.new("yaafehero", parameters).run(:source => get_path(@file))
|
150
136
|
rescue => e
|
151
137
|
raise AudioHeroError, "These was an issue getting stats from #{@basename}"
|
152
138
|
end
|
153
|
-
|
139
|
+
garbage_collect(@file) if options[:gc] == "true"
|
154
140
|
MessagePack.unpack(success)
|
155
141
|
end
|
156
142
|
|
@@ -160,7 +146,6 @@ module AudioHero
|
|
160
146
|
output_options = options[:output_options]
|
161
147
|
effect = options[:effect]
|
162
148
|
output_format = options[:output_format] ? options[:output_format] : "wav"
|
163
|
-
src = @file
|
164
149
|
|
165
150
|
# Default to wav
|
166
151
|
dst = Tempfile.new(["out", ".#{output_format}"])
|
@@ -174,17 +159,56 @@ module AudioHero
|
|
174
159
|
parameters << effect if effect
|
175
160
|
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
|
176
161
|
sox = Cocaine::CommandLine.new("sox", parameters)
|
177
|
-
command = sox.command(source
|
178
|
-
success = sox.run(source
|
162
|
+
command = sox.command(:source => get_path(@file), :dest => get_path(dst))
|
163
|
+
success = sox.run(:source => get_path(@file), :dest => get_path(dst))
|
179
164
|
rescue => e
|
180
165
|
raise AudioHeroError, "There was an error excuting command: #{command}"
|
181
166
|
end
|
182
|
-
|
167
|
+
garbage_collect(@file) if options[:gc] == "true"
|
183
168
|
dst
|
184
169
|
end
|
185
170
|
|
186
171
|
private
|
187
172
|
|
173
|
+
def get_basename(file)
|
174
|
+
case file
|
175
|
+
when String
|
176
|
+
File.basename(file)
|
177
|
+
when Tempfile
|
178
|
+
File.basename(file.path)
|
179
|
+
when File
|
180
|
+
File.basename(file.path)
|
181
|
+
else
|
182
|
+
raise AudioHeroError, "Unknown input file type #{file.class}"
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def get_path(file)
|
187
|
+
case file
|
188
|
+
when String
|
189
|
+
File.expand_path(file)
|
190
|
+
when Tempfile
|
191
|
+
File.expand_path(file.path)
|
192
|
+
when File
|
193
|
+
File.expand_path(file.path)
|
194
|
+
else
|
195
|
+
raise AudioHeroError, "Unknown input file type #{file.class}"
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def garbage_collect(file)
|
200
|
+
case file
|
201
|
+
when String
|
202
|
+
File.delete(file)
|
203
|
+
when Tempfile
|
204
|
+
file.close!
|
205
|
+
when File
|
206
|
+
File.delete(file.path)
|
207
|
+
else
|
208
|
+
raise AudioHeroError, "Unknown input file type #{file.class}"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
188
212
|
def parse_stats(stats)
|
189
213
|
hash = Hash.new { |h, k| h[k] = {} }
|
190
214
|
if stats.include? "Left"
|
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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- litenup
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-07-
|
11
|
+
date: 2016-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,11 +95,6 @@ files:
|
|
95
95
|
- LICENSE.txt
|
96
96
|
- README.md
|
97
97
|
- Rakefile
|
98
|
-
- audio_hero-0.1.0.gem
|
99
|
-
- audio_hero-0.1.1.gem
|
100
|
-
- audio_hero-0.1.2.gem
|
101
|
-
- audio_hero-0.1.3.gem
|
102
|
-
- audio_hero-0.1.4.gem
|
103
98
|
- audio_hero.gemspec
|
104
99
|
- bin/console
|
105
100
|
- bin/setup
|
data/audio_hero-0.1.0.gem
DELETED
Binary file
|
data/audio_hero-0.1.1.gem
DELETED
Binary file
|
data/audio_hero-0.1.2.gem
DELETED
Binary file
|
data/audio_hero-0.1.3.gem
DELETED
Binary file
|
data/audio_hero-0.1.4.gem
DELETED
Binary file
|