audio_glue-sox_adapter 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5a367eaea501961ae8abbebb4e2f306c5f062bde
4
+ data.tar.gz: 42adee62130f495488ddd7012f0b30e57a84c137
5
+ SHA512:
6
+ metadata.gz: 2ab4dfc1f817780594b03ff2c8e773d3301f8c08fd8842a0df4fe4b9badb9142baa4c29e6f60dc3e1f0b272a49df8121cb1d54e0ed0a6785db10999c6b87d0b5
7
+ data.tar.gz: 67f16b1b59b3a55ec010b5730ffdee57f5716e71645883e56c4b701f30d4c1256c46482da4418108bd19b848e28abe33d800d1a67c15441bf39ae10f02009f3f
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 TMX Credit, author Potapov Sergey
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # AudioGlue sox based adapter
2
+
3
+ [![Build Status](https://travis-ci.org/TMXCredit/audio_glue-sox_adapter.png?branch=master)](https://travis-ci.org/TMXCredit/audio_glue-sox_adapter)
4
+
5
+ An [AudioGlue](https://github.com/TMXCredit/audio_glue/) adapter based on the
6
+ [sox](http://sox.sourceforge.net) command line tool.
7
+
8
+
9
+ ## Dependencies
10
+
11
+ * SoX (for sox adapter)
12
+
13
+ ### Debian / Ubuntu
14
+
15
+ ```bash
16
+ apt-get install sox
17
+ ```
18
+
19
+ ### Mac
20
+
21
+ ```bash
22
+ # Note: flac must be installed before sox so it will link during compilation.
23
+ # One of the following:
24
+ sudo port install flac sox
25
+ brew install flac sox
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ For now the adapter supports only `:file` snippet types.
31
+
32
+ Usage example:
33
+
34
+ ```ruby
35
+ adapter = AudioGlue::SoxAdapter.new
36
+ builder = AudioGlue::Builder.new(adapter)
37
+
38
+ # Build binary audio using an instance of AudioGlue::Template:
39
+ builder.build(template)
40
+ ```
41
+
42
+
43
+ ## Credits
44
+
45
+ * [Sergey Potapov](https://github.com/greyblake)
46
+
47
+ ## Copyright
48
+
49
+ Copyright (c) 2013 TMX Credit. See LICENSE.txt for further details.
@@ -0,0 +1,60 @@
1
+ require 'audio_glue'
2
+ require 'sox'
3
+
4
+ # :nodoc:
5
+ module AudioGlue
6
+ # Pretty small adapter based on the +ruby-sox+ library. Handles
7
+ # only local files ( +snippet type = :file+ ).
8
+ class SoxAdapter < AudioGlue::BaseAdapter
9
+ # Write output to a temporary file, read data from it, and remove it.
10
+ #
11
+ # @param snippet_packet [AudioGlue::SnippetPacket]
12
+ #
13
+ # @return [String] audio data as a binary string.
14
+ def build(snippet_packet)
15
+ tmp_file = gen_tmp_filename(snippet_packet.format)
16
+ write(snippet_packet, tmp_file)
17
+ File.binread(tmp_file)
18
+ rescue ::Sox::Error => err
19
+ raise(::AudioGlue::BuildError, err.message)
20
+ ensure
21
+ FileUtils.rm tmp_file if File.exists?(tmp_file)
22
+ end
23
+
24
+
25
+ # Build an output file using the snippet packet, and write it to a file.
26
+ #
27
+ # @param output_file [String] path to a file
28
+ # @param snippet_packet [AudioGlue::SnippetPacket]
29
+ #
30
+ # @return [void]
31
+ def write(snippet_packet, output_file)
32
+ input_files = snippet_packet.snippets.map do |snippet|
33
+ snippet_type = snippet.type
34
+ if snippet_type != :file
35
+ msg = "SoxAdapter doesn't support snippet type " \
36
+ "#{snippet_type.inspect}"
37
+ raise(::AudioGlue::BuildError, msg)
38
+ end
39
+ snippet.source
40
+ end
41
+
42
+ combiner = Sox::Combiner.new(input_files,
43
+ :combine => :concatenate,
44
+ :rate => snippet_packet.rate,
45
+ :channels => snippet_packet.channels)
46
+ combiner.write(output_file)
47
+ end
48
+ private :write
49
+
50
+ # Generate a unique name for the temporary file.
51
+ #
52
+ # @param ext [String] extension of a file
53
+ #
54
+ # @return [String]
55
+ def gen_tmp_filename(ext)
56
+ Dir::Tmpname.make_tmpname ['/tmp/audio-glue-', ".#{ext}"], nil
57
+ end
58
+ private :gen_tmp_filename
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: audio_glue-sox_adapter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - TMX Credit
8
+ - Potapov Sergey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-25 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: audio_glue
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 0.1.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 0.1.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: ruby-sox
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '1.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: jeweler
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 1.8.7
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.7
70
+ - !ruby/object:Gem::Dependency
71
+ name: yard
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: pry
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: metric_fu
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ description: AudioGlue adapter based on sox command line tool
113
+ email:
114
+ - rubygems@tmxcredit.com
115
+ - blake131313@gmail.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files:
119
+ - LICENSE.txt
120
+ - README.markdown
121
+ files:
122
+ - LICENSE.txt
123
+ - README.markdown
124
+ - lib/audio_glue/sox_adapter.rb
125
+ homepage: http://github.com/TMXCredit/audio_glue-sox_adapter
126
+ licenses:
127
+ - MIT
128
+ metadata: {}
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ requirements: []
144
+ rubyforge_project:
145
+ rubygems_version: 2.0.3
146
+ signing_key:
147
+ specification_version: 4
148
+ summary: AudioGlue adapter based on sox command line tool
149
+ test_files: []
150
+ has_rdoc: