lava-audio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/lava/audio_sampler.rb +45 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 50bcac0299ceaec75d1ad841e9e6741034dc9467
4
+ data.tar.gz: d1e87970cf337d3938ea860d4345d12a2d69a3f9
5
+ SHA512:
6
+ metadata.gz: 5a501a5dae052b99127bd93c833f84bcbfa09c0bb34c518028b7e4e07955c0076d3e1b57029407a8cf18e223eb23cc57bf5e8cbd4e9b18d24e4b48ccde7f1bb3
7
+ data.tar.gz: 41b17d995d4aab974cbb55f54277bf3058752ba3bdd43df8b3f24f4e1cac67c680bac829947fdd513ade42d66536723614fd3bf9c4ab319013e9b6dfc65000d1
@@ -0,0 +1,45 @@
1
+ module Lava
2
+
3
+ class AudioSampler
4
+
5
+ SAMPLE_TIME=0.1
6
+ DEFAULT_TMP_DIR = '/tmp/lava/audio/'
7
+
8
+ attr_accessor :dir, :sox
9
+
10
+ def initialize(args = {})
11
+ @dir = args[:dir] || "#{DEFAULT_TMP_DIR}/#{Time.now.to_f}"
12
+ @sox = args[:sox] || which_sox
13
+ if !sox
14
+ raise "It doesn't look like sox is installed. Install it to proceed!"
15
+ end
16
+ FileUtils.mkdir_p(@dir)
17
+ File.directory?(@dir) or raise "Couldn't create session directory for screen grabs"
18
+ end
19
+
20
+ def volume
21
+ ( analyze(sample) * 100 ).to_i
22
+ end
23
+
24
+ def sample
25
+ file = "#{dir}/#{Time.now.to_f}.wav"
26
+ `rec #{file} trim 0 #{SAMPLE_TIME} 2>&1`
27
+ file
28
+ end
29
+
30
+ def analyze(file)
31
+ `#{sox} -t .wav #{file} -n stat 2>&1 | grep 'Maximum amplitude' | sed "s/[^0-9.]//g"`.to_f
32
+ end
33
+
34
+ def which_sox
35
+ result = `which sox`.chop
36
+ if $?.exitstatus == 0
37
+ result
38
+ else
39
+ nil
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lava-audio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - BBC
8
+ - David Buckhurst
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-26 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Sampler for capturing live audio information
15
+ email: david.buckhurst@bbc.co.uk
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/lava/audio_sampler.rb
21
+ homepage: https://github.com/bbc/lava-audio
22
+ licenses:
23
+ - MIT
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.5.1
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Lava Audio
45
+ test_files: []