audio_hero 0.1.0 → 0.1.1

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: a011c7136feae07c844a2a5e40d3c3ffe8e5bf01
4
- data.tar.gz: 5b5d6d327129a36b52c3ed89dea2feb55d19e1da
3
+ metadata.gz: f3648b9480f862ec47b982e8883f1d8e329ee9a3
4
+ data.tar.gz: 8b1228ca980943bb77a1e80c631271c73e7086e1
5
5
  SHA512:
6
- metadata.gz: 9ba8a92edf5eef4c73e70736148842db4aa63fa2750cb934b2eff44b5b9f3ce994aa440b9811c41741d81ee575c58751ff54601bc9ff22b8a2a891e854ad4645
7
- data.tar.gz: 6eb38e772b7b5573cc2fa2daf957d26155475d13c38640be957aca9d6802e65c9aab9152eb290cf5f91961a384fccf5172cd5b9d1b15286342664a70e711aa1d
6
+ metadata.gz: 02d4bbb19b2754a205459014bfeb62ce02e6709f672f0a23762d3a445ebe1ad30a27f8061fb764bf169065ff670599c28cd1bee14278d45e13fea2be5ae03287
7
+ data.tar.gz: 4cd6164c3d846ac9f12bc0edb7c9caa9e3cfa2821b2406fb83bb0a4ed31dce0944d50814f28a7e911c1ec1fa7fe11d516fe04299184844be2764c5aabc30dfa6
data/README.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # AudioHero
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/audio_hero`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ This is a ruby wrapper for [sox](http://sox.sourceforge.net/), the swiss army knife for audio.
4
+ I've implemented sensible defaults for basic operations so converting mp3 to wav is as simple as:
5
+ ```ruby
6
+ AudioHero::Sox.new(mp3file).convert
7
+ ```
6
8
 
7
9
  ## Installation
8
10
 
11
+ Requirements: Obviously, make sure your system has sox installed already.
12
+
9
13
  Add this line to your application's Gemfile:
10
14
 
11
15
  ```ruby
@@ -22,7 +26,66 @@ Or install it yourself as:
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ ###Convert
30
+
31
+ Return the converted audio as ruby temp file object
32
+
33
+ ```ruby
34
+ file = open("url/or/path/to/audio/file")
35
+
36
+ new_file = AudioHero::Sox.new(file).convert({output_options: "-c 1", output_format: "mp3", channel: "left"})
37
+ # Optional: Close the file after you are done for garbage collection.
38
+ new_file.close!
39
+
40
+ # With no options hash it will runs this command by default: `sox -t input.mp3 -c 1 -b 16 -r 16k out.wav`
41
+ AudioHero::Sox.new(file).convert
42
+ ```
43
+ Options(hash):
44
+ * channel (set "left", "right", or leave blank for stereo)
45
+ * input_format (default to "mp3")
46
+ * output_format (default to "wav")
47
+ * output_options (default to "-c 1 -b 16 -r 16k", single channel, 16hz, 16bits)
48
+ * gc (no default, set to "true" to auto close! input file)
49
+
50
+ ###Remove Silence
51
+
52
+ ```ruby
53
+ file = AudioHero::Sox.new(file).remove_silence({input_format: "wav", gc: "true"})
54
+ ```
55
+ Options(hash):
56
+ * silence_duration (default to 0.1 seconds)
57
+ * silence_level (default to 0.03%)
58
+ * input_format (default to "mp3")
59
+ * output_format (default to "wav")
60
+ * gc (no default, set to "true" to auto close! input file)
61
+
62
+ ###Split into multiple files by silence
63
+
64
+ ```ruby
65
+ file_array = AudioHero::Sox.new(file).split_by_silence({input_format: "wav", gc: "true"})
66
+ # file_array == ["path/to/out001.wav", "path/to/out002.wav"]
67
+ ```
68
+ Options(hash):
69
+ * silence_duration (default to 0.1 seconds)
70
+ * silence_level (default to 0.03%)
71
+ * input_format (default to "mp3")
72
+ * output_format (default to "wav")
73
+ * 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
+ * gc (no default, set to "true" to auto close! input file)
75
+
76
+ ###Custom Command
77
+
78
+ Run any sox command with this method.
79
+ ```ruby
80
+ 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: `sox -V3 -t mp3 input.mp3 -c 1 output.wav remix 0 1`
82
+ ```
83
+ Options(hash):
84
+ * global (sox global options, inserted right after `sox`)
85
+ * input_options (sox input options, inserted before input file)
86
+ * output_options (sox output options, inserted before output file)
87
+ * effect (sox effect, inserted after output file)
88
+ * gc (no default, set to "true" to auto close! input file)
26
89
 
27
90
  ## Development
28
91
 
@@ -32,7 +95,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
95
 
33
96
  ## Contributing
34
97
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/audio_hero. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
98
+ Bug reports and pull requests are welcome on GitHub at https://github.com/litenup/audio_hero. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
36
99
 
37
100
 
38
101
  ## License
@@ -1,3 +1,3 @@
1
1
  module AudioHero
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/audio_hero.rb CHANGED
@@ -45,6 +45,7 @@ module AudioHero
45
45
  rescue => e
46
46
  raise AudioHeroError, "There was an error converting #{@basename} to #{output_format}"
47
47
  end
48
+ src.close! if options[:gc] == "true"
48
49
  dst
49
50
  end
50
51
 
@@ -71,6 +72,7 @@ module AudioHero
71
72
  rescue => e
72
73
  raise AudioHeroError, "There was an error converting #{@basename} to #{output_format}"
73
74
  end
75
+ src.close! if options[:gc] == "true"
74
76
  dst
75
77
  end
76
78
 
@@ -105,6 +107,7 @@ module AudioHero
105
107
  rescue => e
106
108
  raise AudioHeroError, "There was an error splitting #{@basename}"
107
109
  end
110
+ src.close! && src2.close! if options[:gc] == "true"
108
111
  Dir["#{dir}/**/*#{format}"]
109
112
  end
110
113
 
@@ -133,7 +136,8 @@ module AudioHero
133
136
  rescue => e
134
137
  raise AudioHeroError, "There was an error excuting command: #{command}"
135
138
  end
136
- dir
139
+ src.close! if options[:gc] == "true"
140
+ dst
137
141
  end
138
142
 
139
143
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audio_hero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - litenup