json-waveform 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/json-waveform +1 -1
- data/json-waveform.gemspec +1 -0
- data/lib/json-waveform.rb +3 -1
- data/lib/json-waveform/version.rb +1 -1
- data/makefile +4 -1
- data/test/json_waveform_test.rb +69 -0
- metadata +16 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5334350a3a74052ba2d9983311f8a7dea5856a22
|
4
|
+
data.tar.gz: 850395b17c1603fbc88956be35cb1b40df7f5fa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 028859a2c897709e158b0a68d6efac492ff0afe0717cbcd597e0d8eb013e2be6da63856caba122435b14f4f881be3eed54dd752c0fd4e5cbd403476a8ced8fc9
|
7
|
+
data.tar.gz: f59a3fb472dea0f4ce2a1166724680657ff30d7d2eee3a63761588236eba3a7a8d902a4e1d96515e706a97af74620ab9988faa757d914e6bd312e10c30719df6
|
data/bin/json-waveform
CHANGED
@@ -8,7 +8,7 @@ optparse = OptionParser.new do |o|
|
|
8
8
|
o.banner = "Usage: json-waveform [options] source_audio [output]"
|
9
9
|
o.version = JsonWaveform::VERSION
|
10
10
|
|
11
|
-
o.on("-s", "--samples SAMPLES", "Samples generated from the original file (i.e.: waveform width) -- Default #{JsonWaveform::DEFAULT_OPTIONS[:samples]}.") do |samples|
|
11
|
+
o.on("-s", "--samples SAMPLES", "Samples generated from the original file (i.e.: waveform width). The result may have ±10% of the samples requested. -- Default #{JsonWaveform::DEFAULT_OPTIONS[:samples]}.") do |samples|
|
12
12
|
options[:samples] = samples.to_i
|
13
13
|
end
|
14
14
|
|
data/json-waveform.gemspec
CHANGED
data/lib/json-waveform.rb
CHANGED
@@ -29,7 +29,9 @@ class JsonWaveform
|
|
29
29
|
# Can be :rms or :peak
|
30
30
|
# Default is :peak.
|
31
31
|
#
|
32
|
-
# :samples => The amount of samples wanted
|
32
|
+
# :samples => The amount of samples wanted. The may have ±10% of the
|
33
|
+
# samples requested.
|
34
|
+
#
|
33
35
|
# Default is 1800.
|
34
36
|
#
|
35
37
|
# :amplitude => The amplitude of the final values
|
data/makefile
CHANGED
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "json-waveform"))
|
2
|
+
|
3
|
+
require "minitest"
|
4
|
+
require "minitest/autorun"
|
5
|
+
require "fileutils"
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
module Helpers
|
9
|
+
def fixture(file)
|
10
|
+
File.join(File.dirname(__FILE__), "fixtures", file)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class JsonWaveformTest < Minitest::Test
|
15
|
+
include Helpers
|
16
|
+
extend Helpers
|
17
|
+
|
18
|
+
def test_generates_waveform
|
19
|
+
result = JsonWaveform.generate(fixture("sample.wav"))
|
20
|
+
|
21
|
+
assert_equal File.read(fixture("sample.peak.json")), JSON.dump(result)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_generates_rms_waveform
|
25
|
+
result = JsonWaveform.generate(fixture("sample.wav"), method: :rms)
|
26
|
+
|
27
|
+
assert_equal File.read(fixture("sample.rms.json")), JSON.dump(result)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_changes_samples
|
31
|
+
result = JsonWaveform.generate(fixture("sample.wav"), samples: 100)
|
32
|
+
|
33
|
+
assert_in_delta 100, result.size, 1
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_changes_amplitude
|
37
|
+
result = JsonWaveform.generate(fixture("sample.wav"), amplitude: 100)
|
38
|
+
|
39
|
+
original = JSON.parse(File.read(fixture("sample.peak.json")))
|
40
|
+
|
41
|
+
assert_in_delta original.max * 100, result.max, 1
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_has_auto_width
|
45
|
+
result = JsonWaveform.generate(fixture("sample.wav"), auto_samples: 10)
|
46
|
+
|
47
|
+
assert_equal 210, result.size
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_raises_error_if_not_given_readable_audio_source
|
51
|
+
assert_raises JsonWaveform::RuntimeError do
|
52
|
+
JsonWaveform.generate(fixture("sample.txt"))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_raises_exception_if_audio_not_exists
|
57
|
+
assert_raises JsonWaveform::RuntimeError do
|
58
|
+
JsonWaveform.generate(fixture("foo.wav"))
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
#def test_raises_deprecation_exception_if_ruby_audio_fails_to_read_source_file
|
63
|
+
# begin
|
64
|
+
# Waveform.generate(fixture("sample.txt"), output("shouldnt_exist.png"))
|
65
|
+
# rescue Waveform::RuntimeError => e
|
66
|
+
# assert_match /Hint: non-WAV files are no longer supported, convert to WAV first using something like ffmpeg/, e.message
|
67
|
+
# end
|
68
|
+
#end
|
69
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-waveform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esteban Pastorino
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 1.6.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4'
|
27
41
|
description: Generate waveform JSON information from audio files, compatible with
|
28
42
|
http://waveformjs.org/.
|
29
43
|
email:
|
@@ -40,6 +54,7 @@ files:
|
|
40
54
|
- lib/json-waveform.rb
|
41
55
|
- lib/json-waveform/version.rb
|
42
56
|
- makefile
|
57
|
+
- test/json_waveform_test.rb
|
43
58
|
homepage: http://github.com/kitop/json-waveform
|
44
59
|
licenses: []
|
45
60
|
metadata: {}
|