audio_hero 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f6648188267d375754831846adec65a3e9dc353b
4
- data.tar.gz: f7426c5fc60293aabafb8f1fd30f2a955ed1255f
3
+ metadata.gz: b233b127c019ea8183e0e87cc3ad04b9674a1013
4
+ data.tar.gz: 1059b99f40c8fae4e5c83c097d55c6c71a181bd6
5
5
  SHA512:
6
- metadata.gz: 453e8140a27247b787c419a71fa3489c877d81411af4ac6b73ffa9a998c942320d849ea16d0f4d552a6a2e154c6d7c54ef2c3c4461ba8015d84d66234f7bf52b
7
- data.tar.gz: ad03392112ca8f646a27eb1f306aeb98272ffac141487014ae29a6eca9257d8b8bacbf882e11634c569edb007d7c9b09dbc5e8158acbcdad7d8bdd5c104df6c6
6
+ metadata.gz: 37e40ed1a23a192aad0cb960ad3390b5d7f4d2bab212eed1fafa0e0c13b17c390510625ecf92ccde4a50b5b296e9c5b9baf508322df9c99327d0e4cb26e4b8e2
7
+ data.tar.gz: 4d6d8ac1b6354b54a34a92fff3c49a8357294f64bbb8e54664073a59a9dc7cc7e7a8e1e97e08568ddb73e1c7efe0fdfd20c6590557f8a4a71f5fcc6f5f889362
data/README.md CHANGED
@@ -93,6 +93,21 @@ file = AudioHero::Sox.new(file_array).concat({output_format: "mp3")
93
93
  Options(hash):
94
94
  * output_format (default to "wav")
95
95
 
96
+ ###Trim
97
+ Cuts portions out of the audio. Any number of positions may be given.
98
+ Usage: file = AudioHero::Sox.new(file).trim({trim_positions: "=10 =20 =30 =40"})
99
+ See sox trim effect for more examples
100
+ Default output to 16bit 16 sample rate Wave audio
101
+
102
+ ```ruby
103
+ file = AudioHero::Sox.new(file).trim({trim_positions: "=10 =20 =30 =40", gc: "true"})
104
+ ```
105
+ Options(hash):
106
+ * trim_positions ("=10 =20 =30 =40" means retrieving audio from 10s-20s and from 30s-40s)
107
+ * input_format (default to "mp3")
108
+ * output_format (default to "wav")
109
+ * output_options (default to "-c 1 -b 16 -r 16k", single channel, 16hz, 16bits)
110
+ * gc (no default, set to "true" to auto close! input file)
96
111
 
97
112
  ###Stats
98
113
  Get statistics report on audio file (support up to 2 channels).
@@ -22,7 +22,7 @@ module AudioHero
22
22
  channel = options[:channel]
23
23
  input_format = options[:input_format] ? options[:input_format] : "mp3"
24
24
  output_format = options[:output_format] ? options[:output_format] : "wav"
25
- output_options = options[:default] ? "-c 1 -b 16 -r 16k" : options[:output_options]
25
+ output_options = options[:output_options] ? options[:output_options] : "-c 1 -b 16 -r 16k"
26
26
  case channel
27
27
  when "left"
28
28
  channel = "remix 1"
@@ -80,7 +80,6 @@ module AudioHero
80
80
  # Returns an array of the full path of the splitted files, can split two input files at one go using {file2: file} option.
81
81
  # Remember its good practice to remove the temp directory after use.
82
82
  # FileUtils.remove_entry tempdir
83
-
84
83
  def split_by_silence(options={})
85
84
  above_period_duration = options[:above_period_duration] || "0.5"
86
85
  above_period_threshold = options[:above_period_threshold] || "0.05"
@@ -129,6 +128,35 @@ module AudioHero
129
128
  dst
130
129
  end
131
130
 
131
+ # Cuts portions out of the audio. Any number of positions may be given
132
+ # Usage: file = AudioHero::Sox.new(file).trim({trim_positions: "=10 =20 =30 =40"})
133
+ # trim_positions "=10 =20 =30 =40" means retrieving audio from 10s-20s and from 30s-40s, and joining them into one file.
134
+ # See sox trim effect for more examples
135
+ # Default output to 16bit 16 sample rate Wave audio
136
+ def trim(options={})
137
+ raise AudioHeroError, "Trim parameters not given" unless options[:trim_positions]
138
+ input_format = options[:input_format] ? options[:input_format] : "mp3"
139
+ output_format = options[:output_format] ? options[:output_format] : "wav" # Default to wav
140
+ output_options = options[:output_options] ? options[:output_options] : "-c 1 -b 16 -r 16k"
141
+ trim_positions = options[:trim_positions]
142
+ effect = "trim #{trim_positions}"
143
+ dst = Tempfile.new(["out", ".#{output_format}"])
144
+ begin
145
+ parameters = []
146
+ parameters << "-t #{input_format}"
147
+ parameters << ":source"
148
+ parameters << output_options if output_options
149
+ parameters << ":dest"
150
+ parameters << effect
151
+ parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
152
+ success = Cocaine::CommandLine.new("sox", parameters).run(:source => get_path(@file), :dest => get_path(dst))
153
+ rescue => e
154
+ raise AudioHeroError, "There was an error trimming #{@basename} using positions #{trim_positions}"
155
+ end
156
+ garbage_collect(@file) if options[:gc] == "true"
157
+ dst
158
+ end
159
+
132
160
  def stats(options={})
133
161
  input_format = options[:input_format] ? options[:input_format] : "mp3"
134
162
  begin
@@ -1,3 +1,3 @@
1
1
  module AudioHero
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
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.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - litenup
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-16 00:00:00.000000000 Z
11
+ date: 2016-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler