easyaudio_utils 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c06f61c96a78d7a1a769955522e3176b3c682412ae5f8063a0c7889f2bfb1367
4
+ data.tar.gz: 70daa115660f96f34b4a88ed81ddfe2463bc2a213cb4bc7676f81ad353a8a458
5
+ SHA512:
6
+ metadata.gz: '0132212489272418347971651af49b643b6fc57d23c79571539433eae56965c763329492d44fcc280c539bcb62fab1feb61a3d38856e2dbae6a315239c1b4fc5'
7
+ data.tar.gz: 8c2610f62980859fdfac33f3c538140269378ea2d8648dc03e6c46b9745612c843f036a2d1c2d75795dd126cced8f327363141d9acddbc1c5cad8b5d4ee1e00f
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: easyaudio_utils.rb
4
+
5
+ require 'c32'
6
+ require 'wavefile'
7
+
8
+ # requirements:
9
+ # `apt-get install mplayer sox vorbis-tools
10
+
11
+
12
+ module CommandHelper
13
+ using ColouredText
14
+
15
+ def list(a=@commands)
16
+
17
+ format_command = ->(s) do
18
+ command, desc = s.split(/\s+#\s+/,2)
19
+ " %s %s %s" % ['*'.blue, command, desc.to_s.light_black]
20
+ end
21
+
22
+ s = a.map {|x| format_command.call(x) }.join("\n")
23
+ puts s
24
+ end
25
+
26
+ def search(s)
27
+ list @commands.grep Regexp.new(s)
28
+ end
29
+
30
+ end
31
+
32
+ module WavTool
33
+ include WaveFile
34
+
35
+ def wav_silence(filename, duration: 1)
36
+
37
+ square_cycle = [0] * 100 * duration
38
+ buffer = Buffer.new(square_cycle, Format.new(:mono, :float, 44100))
39
+
40
+ Writer.new(filename, Format.new(:mono, :pcm_16, 22050)) do |writer|
41
+ 220.times { writer.write(buffer) }
42
+ end
43
+
44
+ end
45
+
46
+ def wav_concat(files, save_file='audio.wav')
47
+
48
+ Writer.new(save_file, Format.new(:stereo, :pcm_16, 22050)) do |writer|
49
+
50
+ files.each do |file_name|
51
+
52
+ Reader.new(file_name).each_buffer(samples_per_buffer=4096) do |buffer|
53
+ writer.write(buffer)
54
+ end
55
+
56
+ end
57
+ end
58
+
59
+ end
60
+
61
+ def duration(file_name)
62
+ Reader.new(file_name).total_duration
63
+ end
64
+
65
+ end
66
+
67
+
68
+ class EasyAudioUtils
69
+ extend CommandHelper
70
+ include WavTool
71
+
72
+ @commands = "
73
+ * capture_desktop # records the desktop
74
+ * concat_files # stiches wav files together
75
+ * convert # converts a file from 1 format to another #wav #ogg
76
+ * duration # return the duration for a wav or ogg
77
+ * generate_silence # generates silence in a wav file
78
+ * play # plays using mplayer
79
+ * record # alias for capture_desktop
80
+ ".strip.lines.map {|x| x[/(?<=\* ).*/]}.sort
81
+
82
+
83
+ def initialize(audio_in=nil, audio_out='audio.wav', out: audio_out,
84
+ working_dir: '/tmp')
85
+
86
+ @file_in, @file_out, @working_dir = audio_in, out, working_dir
87
+
88
+ end
89
+
90
+ # records audio in mono audio
91
+ # tested with .flac
92
+ #
93
+ def capture()
94
+
95
+ command = "rec -c 1 -r 8000 -t alsa default #{@file_out} " +
96
+ "silence 1 0.1 5% 5 1.0 5%"
97
+ run command, show
98
+
99
+ end
100
+
101
+ def concat_files(files=[])
102
+ wav_concat files, @file_out
103
+ end
104
+
105
+ alias concat concat_files
106
+
107
+ def convert()
108
+
109
+ if File.extname(@file_in) == '.ogg' then
110
+ ogg_to_wav() if File.extname(@file_out) == '.wav'
111
+ end
112
+
113
+ end
114
+
115
+ def duration()
116
+
117
+ case File.extname(@file_in)
118
+ when '.ogg'
119
+ ogg_duration()
120
+ when '.wav'
121
+ wav_duration()
122
+ end
123
+
124
+ end
125
+
126
+ # silence duration in seconds
127
+ #
128
+ def generate_silence(duration)
129
+ wav_silence @out_file, duration: duration
130
+ end
131
+
132
+ alias record capture
133
+
134
+ def play(show: false)
135
+ command = "mplayer #{@file_out}"
136
+ run command, show
137
+ end
138
+
139
+
140
+ private
141
+
142
+ def ogg_duration()
143
+ OggInfo.open(@file_in) {|ogg| ogg.length.to_i }
144
+ end
145
+
146
+ def ogg_to_wav()
147
+ `oggdec #{@file_in} #{@file_out}`
148
+ end
149
+
150
+
151
+ def run(command, show: false)
152
+
153
+ if show then
154
+ command
155
+ else
156
+ puts "Using ->" + command
157
+ system command
158
+ end
159
+
160
+ end
161
+
162
+ end
163
+
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easyaudio_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEXjCCAsagAwIBAgIBATANBgkqhkiG9w0BAQsFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTkwNTA1MjAwMTA3WhcN
15
+ MjAwNTA0MjAwMTA3WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggGiMA0GCSqGSIb3DQEBAQUAA4IBjwAwggGKAoIBgQDoxk13
17
+ MbIqow61gWceYZGgouCQuw81pMiEobLdRuXVXlBQ7H5B/1jKiCSfyzhx60Ky+Ten
18
+ wJ6/rXA8sCvab2LyOFTYoyuM6/TtaB9LNIX6nfhI5ze13o/iV7woa2848IGVRz28
19
+ fGidPL34M4NrA5+l4h1TT6OnZNvykWpyHGuAvcGDuOE5odxgsFTJ+jiP0IAL5hJY
20
+ ffQI2yokAq7kIYkC6BjNilIOd82L4/Hf6ZhOJQKm9kCPvH3b4UsGpAWO+zIJ9rtk
21
+ AnHPcJIX61FUMX/945iP7V20KsdJGbkGKKCPz3ev6RG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
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: c32
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 0.2.0
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.2'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.2.0
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '0.2'
60
+ - !ruby/object:Gem::Dependency
61
+ name: wavefile
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 1.1.0
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.1'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.1.0
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: '1.1'
80
+ description:
81
+ email: james@jamesrobertson.eu
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - lib/easyaudio_utils.rb
87
+ homepage: https://github.com/jrobertson/easyaudio_utils
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 3.0.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: A wrapper for various command-line audio utilities under GNU/Linux.
110
+ test_files: []
metadata.gz.sig ADDED
Binary file