wave_to_json 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODE2Yjk0YzIyODc2YzFiODk1YTU1ZmZjMjIwYTUwYTZjOTcyMzY5Yw==
5
+ data.tar.gz: !binary |-
6
+ ZjIxNmI2YmVjYjZlYTM0NDYwZWM5NzE5YTk1ODFlOWViODc4M2Y1Yg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MzQ1ZjVkYWNlYzMyODQ5Y2IxYWJiM2NhMjQ1N2ZmMmQ4ZmQ3ZTVlMWYwNDdj
10
+ NmQ2NWRhMGVhNmE0MzFmYzYyMmYxMWE1ZmI3NTY4YWNhMzYyMWE3OWRlMDVk
11
+ NjVlMmNlZTA5NTI1MDczMzA0OTUzNGU0YTEwOWE0MmRhMjhkM2M=
12
+ data.tar.gz: !binary |-
13
+ YWY4YWViZWUzMTdhYzFlODNjZmUyMzc1YzE3Mjg5MGFiYTQ4Y2M4NDA1MDU3
14
+ NzNhZjk3NWUwYjM5YjVlY2I3ODA1MGM5MmFlNjVjNTIxMmE0NTU1YWI0YTk3
15
+ ODE4M2E0NTdlY2JiY2E1ZGI4NjhlNTY4NjdhNmQ4YWI4NGY3OGY=
@@ -0,0 +1,13 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+ /tmp
10
+
11
+ .idea
12
+ .DS_store
13
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ wave_to_json (0.0.1)
5
+ oj (~> 2.0)
6
+ thor (~> 0.19)
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.2.4)
12
+ oj (2.10.2)
13
+ rake (10.1.0)
14
+ rspec (2.14.1)
15
+ rspec-core (~> 2.14.0)
16
+ rspec-expectations (~> 2.14.0)
17
+ rspec-mocks (~> 2.14.0)
18
+ rspec-core (2.14.4)
19
+ rspec-expectations (2.14.0)
20
+ diff-lcs (>= 1.1.3, < 2.0)
21
+ rspec-mocks (2.14.2)
22
+ thor (0.19.1)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ rake
29
+ rspec
30
+ wave_to_json!
@@ -0,0 +1,52 @@
1
+ wave-to-json
2
+ =============
3
+ generate a waveform in json format
4
+
5
+ Installation
6
+ ============
7
+
8
+ wave-to-json require `sox`.
9
+
10
+ install it via `brew` or `apt`
11
+ ```sh
12
+ brew install sox
13
+ ```
14
+ or
15
+ ```sh
16
+ sudo apt-get install sox libsox-fmt-mp3
17
+ ```
18
+
19
+ Usage by examples
20
+ -----------------
21
+
22
+ convert mp3 file to json format
23
+
24
+ ```ruby
25
+ WaveToJson.new(SOURCE, DESTINATION, OPTIONS).generate
26
+ ```
27
+
28
+ * Both channels
29
+
30
+ ```ruby
31
+ WaveToJson.new('test.mp3', 'test.json').generate
32
+ ```
33
+ * Left channel
34
+
35
+ Generate from left channel
36
+ ```ruby
37
+ WaveToJson.new('test.mp3', 'test.json', channel: :left).generate
38
+ ```
39
+
40
+ * Right channel
41
+
42
+ Generate json format from right channel
43
+ ```ruby
44
+ WaveToJson.new('test.mp3', 'test.json', channel: :right).generate
45
+ ```
46
+
47
+ CLI Usage
48
+ -----------------
49
+ ```sh
50
+ $ wave_to_json generate song.mp3 waveform.json
51
+ ```
52
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'wave_to_json/cli'
3
+
4
+ WaveToJson::CLI.start(ARGV)
data/c ADDED
@@ -0,0 +1 @@
1
+ irb -r ./lib/wave_to_json.rb
@@ -0,0 +1,73 @@
1
+ require 'oj'
2
+ require 'wave_to_json/version'
3
+ require 'wave_to_json/shell_command'
4
+ require 'wave_to_json/audio'
5
+
6
+ class WaveToJson
7
+ DEFAULT_PIXEL_PER_SECOND = 1000 / 30.0
8
+
9
+ def initialize(source, destination, options = {})
10
+ @filename = source
11
+ @output_path = destination
12
+ @pixel_per_second = options.fetch(:pixel_per_second, DEFAULT_PIXEL_PER_SECOND)
13
+ @channel = options.fetch(:channel, :both)
14
+ @audio = Audio.new(@filename)
15
+ end
16
+
17
+ def raw_values
18
+ min_values = []
19
+ max_values = []
20
+
21
+ contents = @audio.raw_data(channel: @channel)
22
+ segment_size = (contents.length.to_f / width).to_i
23
+ current_index = 0
24
+ min = Audio::MAX_VALUE
25
+ max = Audio::MIN_VALUE
26
+
27
+ contents.each do |value|
28
+ if current_index == segment_size
29
+ max_values.push(max)
30
+ min_values.push(min)
31
+
32
+ current_index = 0
33
+ min = Audio::MAX_VALUE
34
+ max = Audio::MIN_VALUE
35
+ else
36
+ min = value < min ? value : min
37
+ max = value > max ? value : max
38
+ current_index+=1
39
+ end
40
+ end
41
+
42
+ if current_index != 0
43
+ max_values.push(max)
44
+ min_values.push(min)
45
+ end
46
+
47
+ [min_values, max_values]
48
+ end
49
+
50
+ def width
51
+ duration_in_millisecond = @audio.duration * 1000
52
+ @width ||= ( duration_in_millisecond/ @pixel_per_second).round
53
+ end
54
+
55
+ def calculate_ratios(mins, maxs)
56
+ max = 0
57
+ results = (0..mins.length-1).map do |i|
58
+ height = maxs[i] - mins[i]
59
+ max = height > max ? height : max
60
+ height
61
+ end
62
+
63
+ results.map { |result| (result / max.to_f).round(6) }
64
+ end
65
+
66
+ def generate
67
+ File.open(@output_path, 'w') do |file|
68
+ values = raw_values
69
+ converted_values = calculate_ratios(*values)
70
+ file.write(Oj.dump(converted_values))
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,42 @@
1
+ class WaveToJson
2
+ class Audio
3
+ MAX_VALUE = 2**16
4
+ MIN_VALUE = -(2**16)
5
+
6
+ def initialize(audio_path)
7
+ @path = audio_path
8
+ end
9
+
10
+ def duration
11
+ return @duration if @duration
12
+ @duration = ShellCommand.new(['soxi', '-D', @path]).run_and_return_output_if_success.to_f
13
+ end
14
+
15
+ def number_of_channels
16
+ return @number_of_channels if @number_of_channels
17
+ @number_of_channels = ShellCommand.new(['soxi', '-c', @path]).run_and_return_output_if_success.to_i
18
+ end
19
+
20
+ def raw_data(options = {})
21
+ command = [ 'sox', @path, '-t', 'raw', '-r', '44100', '-c', '1', '-e', 'signed-integer', '-L', '-' ]
22
+ if options[:channel] == :left
23
+ command.concat(%w(remix 1 1))
24
+ elsif options[:channel] == :right
25
+ command.concat(%w(remix 2 2))
26
+ end
27
+
28
+ ShellCommand.new(command).run_and_return_output_if_success.unpack('l*')
29
+ end
30
+
31
+ def generate_raw_file(raw_file_path, options={})
32
+ command = [ 'sox', @path, '-t', 'raw', '-r', '44100', '-c', '1', '-e', 'signed-integer', '-L', raw_file_path ]
33
+ if options[:channel] == :left
34
+ command.concat(%w(remix 1 1))
35
+ elsif options[:channel] == :right
36
+ command.concat(%w(remix 2 2))
37
+ end
38
+
39
+ ShellCommand.new(command).execute
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ require 'thor'
2
+ require 'wave_to_json'
3
+
4
+ class WaveToJson
5
+ class CLI < Thor
6
+ def initialize(args = [], opts = {}, config = {})
7
+ super(args, opts, config)
8
+ end
9
+
10
+ desc 'generate MP3_PATH JSON_PATH', 'generate json file from mp3 file'
11
+ def generate(mp3_path, json_path)
12
+ WaveToJson.new(mp3_path, json_path).generate
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ class WaveToJson
2
+ class ShellCommand
3
+ attr_accessor :output
4
+
5
+ def initialize(commands)
6
+ @commands = commands
7
+ end
8
+
9
+ def execute
10
+ IO.popen('-') do |p|
11
+ if p.nil?
12
+ $stderr.close
13
+ exec *@commands
14
+ end
15
+ @output = p.read
16
+ end
17
+ end
18
+
19
+ def run_and_return_output_if_success
20
+ self.execute
21
+ return @output if self.success?
22
+ end
23
+
24
+ def success?
25
+ return false if $?.nil?
26
+ $?.exitstatus == 0 ? true : false
27
+ end
28
+
29
+ def status
30
+ $?.exitstatus unless $?.nil?
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ class WaveToJson
2
+ VERSION="0.1.0"
3
+ end
@@ -0,0 +1 @@
1
+ [5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,0.082764,0.159338,0.142938,0.153859,0.08285,0.135102,0.211381,0.137945,0.150738,0.225684,0.232914,0.231077,0.190457,0.132433,0.250477,0.072102,0.024254,0.000225,5.2e-05,6.9e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,6.9e-05,0.012066,0.307427,0.253077,0.282757,0.253788,0.223276,0.217538,0.151728,0.100291,0.284109,0.259457,0.183159,0.161454,0.157866,0.293471,0.175791,0.16669,0.207847,0.063746,0.03899,0.019157,0.0207,0.012534,0.011043,0.008686,0.007819,0.432579,0.776014,0.375542,0.292656,0.333397,0.375594,0.364707,0.342793,0.262491,0.193319,0.148643,0.154017,0.125863,0.098072,0.105631,0.108734,0.103932,0.254499,0.631792,0.340106,0.255504,0.259457,0.229066,0.214469,0.188811,0.159773,0.170365,0.148261,0.14443,0.159617,0.119188,0.107226,0.118529,0.099927,0.388631,0.978762,0.892514,0.764311,0.6868,0.517007,0.526334,0.701519,0.87464,0.669637,0.696266,0.56196,0.321556,0.260202,0.295707,0.442859,0.32433,0.390328,0.385891,0.182899,0.703841,0.495648,0.680853,0.364255,0.534794,0.692537,0.282549,0.261554,0.303162,0.465986,0.474099,0.308588,0.293539,0.29562,0.5906,1.0,0.717069,0.667573,0.524843,0.167123,0.439738,0.813772,0.599269,0.533564,0.208626,0.253648,0.212214,0.25859,0.735793,0.675514,0.509621,0.557938,0.388683,0.453088,0.622343,0.467511,0.735272,0.73347,0.87946,0.828905,0.88908,0.543462,0.273361,0.193839,0.771523,0.5207,0.897074,0.644741,0.614299,0.823671,0.68744,0.593061,0.617194,0.549391,0.466229,0.599043,0.69689,0.603932,0.626001,0.636732,0.708852,0.692728,0.786241,0.533459,0.226067,0.434728,0.431382,0.674056,0.561163,0.525051,0.205524,0.291806,0.333691,0.629676,0.77844,0.677403,0.542838,0.374467,0.199664,0.124302,0.362227,0.46954,0.253632,0.648227,0.634062,0.337939,0.340314,0.501941,0.567092,0.583908,0.52545,0.558181,0.570906,0.513036,0.520093,0.175462,0.496272,0.572987,0.576801,0.52961,0.417236,0.424639,0.567404,0.553708,0.547536,0.532107,0.568167,0.497659,0.51829,0.198069,0.135137,0.185759,0.109514,0.181547,0.223796,0.279237,0.356194,0.670937,0.464478,0.188083,0.476943,0.517822,0.505704,0.491764,0.302815,0.098644,0.390555,0.450002,0.390659,0.171683,0.303856,0.880327,0.580562,0.531379,0.667071,0.608162,0.23047,0.1924,0.29094,0.625845,0.574564,0.468898,0.676728,0.64996,0.150394,0.153358,0.107052,0.264745,0.50085,0.491783,0.451181,0.447523,0.153081,0.406383,0.471481,0.548958,0.605129,0.586578,0.509552,0.557418,0.447315,0.455168,0.249211,0.121459,0.089092,0.101279,0.11742,0.197358,0.198381,0.138293,0.087445,0.335789,0.482785,0.556135,0.449863,0.384158,0.316615,0.346052,0.22657,0.677178,0.555875,0.132,0.148348,0.552373,0.740577,0.629607,0.433758,0.204622,0.157727,0.092732,0.145678,0.27825,0.43322,0.459502,0.158767,0.10629,0.242744,0.325041,0.316788,0.166603,0.222513,0.454215,0.364741,0.186783,0.164383,0.192972,0.394438,0.468846,0.465223,0.206494,0.419489,0.557037,0.475469,0.389272,0.521099,0.277418,0.447193,0.456607,0.459294,0.440397,0.198675,0.157883,0.146874,0.387677,0.444246,0.19318,0.381037,0.333518,0.149492,0.070074,0.065688,0.066346,0.203408,0.493395,0.482993,0.488801,0.609358,0.361135,0.296869,0.199282,0.118217,0.147602,0.202211,0.120176,0.427014,0.149631,0.627076,0.722392,0.55428,0.468846,0.303595,0.09164,0.332148,0.330813,0.206649,0.195519,0.079505,0.566156,0.720953,0.674821,0.612999,0.609843,0.647395,0.606862,0.483028,0.604261,0.558788,0.44636,0.151104,0.338459,0.191221,0.13382,0.273777,0.636316,0.50059,0.534343,0.586612,0.546132,0.532228,0.139073,0.445338,0.513783,0.398721,0.43088,0.45971,0.630647,0.760324,0.758226,0.686054,0.653132,0.648157,0.576402,0.590202,0.527183,0.463472,0.501422,0.606706,0.587098,0.237388,0.06997,0.043879,0.500243,0.493776,0.384297,0.394439,0.154675,0.175964,0.167348,0.129018,0.075032,0.395375,0.475157,0.386533,0.083596,0.082816,0.061718,0.396085,0.391006,0.283485,0.151624,0.342013,0.284907,0.404736,0.395357,0.349433,0.174301,0.177993,0.130335,0.132693,0.599164,0.597828,0.535244,0.467893,0.489043,0.405742,0.144673,0.082625,0.358153,0.308866,0.117107,0.125048,0.406123,0.343903,0.162789,0.099372,0.090791,0.368399,0.205038,0.157918,0.138899,0.154745,0.165927,0.144517,0.465916,0.672739,0.604487,0.654086,0.509639,0.456607,0.331056,0.2364,0.1359,0.188516,0.193977,0.118113,0.115599,0.093859,0.126001,0.137027,0.117628,0.110467,0.328837,0.296678,0.163413,0.148313,0.114628,0.106948,0.519088,0.573576,0.248448,0.385839,0.671683,0.744443,0.589039,0.591293,0.44806,0.48549,0.512708,0.728009,0.581516,0.565098,0.486339,0.200356,0.279168,0.238513,0.209371,0.201674,0.29068,0.27955,0.584896,0.534066,0.161801,0.143407,0.134392,0.57016,0.668059,0.665181,0.552114,0.520423,0.429146,0.224593,0.374935,0.496012,0.498596,0.504663,0.157172,0.172671,0.360182,0.396623,0.241826,0.16005,0.077858,0.277608,0.196543,0.20483,0.2817,0.336518,0.527149,0.726552,0.629642,0.690632,0.593026,0.612166,0.433255,0.223727,0.061163,0.103255,0.070351,0.091571,0.296245,0.402292,0.476786,0.415051,0.425349,0.424829,0.433237,0.344873,0.087774,0.131705,0.150532,0.415866,0.481242,0.408966,0.347959,0.499601,0.660119,0.709285,0.599025,0.560504,0.269859,0.29999,0.343643,0.135588,0.33038,0.216359,0.297927,0.299954,0.243627,0.277504,0.091536,0.506692,0.681096,0.559776,0.682847,0.624042,0.56144,0.489823,0.20691,0.239329,0.152855,0.571357,0.643979,0.705887,0.652144,0.574997,0.426182,0.190406,0.221161,0.148018,0.167331,0.31112,0.283607,0.305641,0.525588,0.556465,0.453452,0.26334,0.145192,0.192209,0.224593,0.591865,0.470077,0.481242,0.428851,0.335668,0.162841,0.158437,0.372802,0.333969,0.607884,0.657796,0.620003,0.367342,0.130387,0.143597,0.143996,0.095749,0.079851,0.525138,0.631428,0.52564,0.273326,0.26549,0.379841,0.428747,0.373062,0.47169,0.386984,0.163257,0.432925,0.519486,0.428505,0.398946,0.308207,0.207949,0.269476,0.228822,0.097517,0.592629,0.63564,0.543809,0.720242,0.653288,0.547987,0.419559,0.166499,0.202645,0.147238,0.118997,0.102528,0.519555,0.712614,0.625117,0.54497,0.621372,0.570247,0.186817,0.29042,0.564717,0.516348,0.37301,0.241132,0.122222,0.1139,0.140893,0.217832,0.354339,0.58682,0.59041,0.700218,0.616397,0.488193,0.428938,0.238567,0.196786,0.77662,0.81951,0.797371,0.674162,0.351045,0.209875,0.097812,0.068999,0.208783,0.692452,0.49648,0.108231,0.620557,0.934295,0.586855,0.52597,0.433671,0.374518,0.258053,0.262075,0.094553,0.459467,0.512066,0.460074,0.219427,0.241878,0.757931,0.652699,0.550085,0.554332,0.490084,0.440709,0.26367,0.125741,0.728373,0.522399,0.26627,0.186627,0.276897,0.300717,0.414479,0.40451,0.507975,0.3693,0.421466,0.669481,0.70743,0.753978,0.627683,0.684182,0.513904,0.355622,0.289761,0.263565,0.163188,0.168406,0.419975,0.451736,0.177161,0.145765,0.255555,0.249696,0.222669,0.372959,0.36058,0.29692,0.451024,0.571201,0.722045,0.503138,0.800024,0.671856,0.571461,0.480202,0.345983,0.257671,0.155871,0.164627,0.297684,0.677265,0.642003,0.521359,0.104521,0.226379,0.532939,0.801204,0.253788,0.372664,0.587133,0.536146,0.491314,0.252262,0.217,0.359263,0.529368,0.466073,0.289119,0.09509,0.134444,0.317239,0.726951,0.748847,0.607278,0.685517,0.601973,0.582678,0.13942,0.107503,0.176068,0.74779,0.610069,0.671527,0.587549,0.607434,0.569762,0.563053,0.473735,0.399674,0.366596,0.370237,0.292067,0.127613,0.102562,0.088034,0.088867,0.069658,0.04296,0.055251,0.060868,0.042353,0.036979,0.024462,0.172723,0.538296,0.60414,0.703599,0.727592,0.327399,0.664835,0.753337,0.55988,0.375628,0.673624,0.62035,0.618408,0.60674,0.685794,0.619205,0.390624,0.189869,0.082261,0.06489,0.583024,0.762474,0.69429,0.624388,0.223397,0.566571,0.485125,0.162666,0.198536,0.356212,0.481328,0.619552,0.43433,0.632849,0.740161,0.388977,0.410821,0.482733,0.408117,0.368902,0.463368,0.203599,0.150411,0.238566,0.139922,0.717225,0.71414,0.76015,0.703442,0.635432,0.529974,0.414029,0.346798,0.60251,0.461062,0.329479,0.272736,0.195763,0.50104,0.669168,0.259977,0.334004,0.280347,0.277608,0.293575,0.229482,0.269876,0.511979,0.596477,0.352779,0.399674,0.676658,0.690701,0.609375,0.756024,0.690701,0.58526,0.536198,0.462657,0.143719,0.134687,0.142627,0.141795,0.346486,0.657622,0.581238,0.553326,0.560417,0.555321,0.667695,0.613536,0.573229,0.342048,0.259023,0.397004,0.47559,0.292916,0.31027,0.465708,0.474897,0.222097,0.19422,0.180351,0.403713,0.534291,0.525935,0.607313,0.533858,0.571599,0.513921,0.164141,0.281214,0.356818,0.152526,0.18817,0.567386,0.677335,0.749437,0.603499,0.521029,0.549131,0.334264,0.623141,0.560626,0.36488,0.129572,0.145678,0.158386,0.137582,0.130162,0.120817,0.141656,0.195798,0.58344,0.621043,0.329964,0.158108,0.483132,0.538486,0.533771,0.549617,0.309542,0.207378,0.124441,0.332738,0.497191,0.453365,0.404303,0.181009,0.19193,0.164782,0.316685,0.396571,0.324989,0.328768,0.370358,0.143927,0.342689,0.291581,0.441628,0.220294,0.181894,0.263444,0.507038,0.482559,0.556656,0.463281,0.506623,0.512968,0.371606,0.314188,0.387469,0.420478,0.398426,0.388683,0.219444,0.14774,0.305572,0.444888,0.493672,0.436844,0.487882,0.404545,0.207378,0.157813,0.176433,0.183106,0.614993,0.689539,0.45945,0.442634,0.561336,0.455099,0.327347,0.177022,0.154623,0.137079,0.145973,0.141968,0.279116,0.210499,0.182899,0.163864,0.16799,0.149925,0.109237,0.099823,0.123279,0.285323,0.17723,0.169307,0.095038,0.178877,0.154624,0.135658,0.100014,0.315211,0.719653,0.778284,0.416681,0.511303,0.56626,0.203286,0.256908,0.212059,0.561891,0.617472,0.467858,0.377223,0.403974,0.20828,0.188169,0.158905,0.286034,0.176762,0.263306,0.669169,0.738774,0.638674,0.510835,0.44858,0.482022,0.31984,0.437605,0.252939,0.256579,0.243022,0.260964,0.213099,0.122811,0.133317,0.255886,0.383465,0.247096,0.200565,0.218664,0.222461,0.179882,0.206234,0.486252,0.540186,0.630439,0.692677,0.533945,0.354097,0.472417,0.495233,0.505548,0.537082,0.615946,0.621615,0.462675,0.161419,0.135918,0.121511,0.314205,0.502219,0.392618,0.51536,0.420045,0.163534,0.288825,0.193353,0.397767,0.529125,0.407458,0.484536,0.413144,0.558267,0.193076,0.30682,0.397767,0.413422,0.400177,0.236278,0.150653,0.138154,0.150393,0.145626,0.151676,0.123227,0.179467,0.132034,0.140893,0.136368,0.11872,0.11768,0.110537,0.179623,0.718439,0.815385,0.484206,0.635467,0.555338,0.231372,0.172654,0.246784,0.325578,0.582972,0.463575,0.395565,0.235966,0.284681,0.156062,0.448112,0.517232,0.457526,0.352363,0.273586,0.254932,0.267397,0.368711,0.438837,0.452307,0.373149,0.58044,0.653219,0.590912,0.561631,0.546877,0.5591,0.332478,0.231649,0.183385,0.541399,0.599667,0.265819,0.272528,0.309767,0.485489,0.497607,0.475053,0.218404,0.254603,0.356974,0.379338,0.260636,0.238185,0.218491,0.295447,0.394734,0.512412,0.730418,0.580337,0.484935,0.573749,0.525398,0.508148,0.165251,0.448996,0.474013,0.40321,0.403609,0.504958,0.539336,0.593929,0.558579,0.543324,0.741739,0.448719,0.44702,0.260965,0.168701,0.198363,0.156652,0.130665,0.168146,0.116241,0.234042,0.660553,0.534482,0.572431,0.551766,0.434207,0.558805,0.335425,0.444645,0.527027,0.465067,0.405291,0.353282,0.403731,0.457595,0.428834,0.432301,0.358882,0.457196,0.568323,0.549738,0.335737,0.175271,0.554124,0.61319,0.53866,0.449811,0.313027,0.253944,0.249437,0.176849,0.16272,0.161142,0.363614,0.503207,0.562446,0.563971,0.448025,0.183697,0.166811,0.257619,0.329461,0.335217,0.461669,0.499359,0.502202,0.516071,0.600378,0.468604,0.451059,0.206026,0.205818,0.220675,0.477012,0.542162,0.57576,0.517978,0.460039,0.254187,0.209008,0.136611,0.146285,0.286467,0.604608,0.5164,0.509102,0.210031,0.138275,0.271454,0.304982,0.213533,0.208939,0.169671,0.141465,0.462259,0.497382,0.581637,0.369265,0.56014,0.67737,0.189834,0.467598,0.808952,0.631739,0.475764,0.373808,0.254308,0.197445,0.302347,0.208349,0.188603,0.156357,0.144378,0.163864,0.172168,0.14046,0.227419,0.206823,0.177924,0.180264,0.383065,0.260965,0.218144,0.22976,0.221109,0.228789,0.20672,0.172758,0.337887,0.284647,0.226986,0.211678,0.193388,0.445772,0.446725,0.570697,0.37731,0.556516,0.525259,0.489667,0.436601,0.411012,0.703218,0.422177,0.389723,0.806265,0.817203,0.650931,0.479248,0.463645,0.670693,0.520024,0.384331,0.252436,0.82003,0.784751,0.460524,0.516105,0.482316,0.440796,0.389723,0.440449,0.755105,0.698571,0.580162,0.688516,0.498578,0.447955,0.436531,0.433098,0.471412,0.353455,0.174716,0.152474,0.099008,0.057852,0.033459,0.023907,0.018879,0.013661,0.009812,0.0082,0.00052,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05,5.2e-05]
Binary file
@@ -0,0 +1,8 @@
1
+ require 'wave_to_json'
2
+ require 'fileutils'
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.run_all_when_everything_filtered = true
7
+ config.filter_run :focus
8
+ end
File without changes
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe WaveToJson do
4
+ let(:esp) { 0.001 }
5
+
6
+ describe '.generate' do
7
+ let(:mp3_path) { File.join(File.dirname(__FILE__), 'fixtures', 'test.mp3') }
8
+ let(:expected_output) { File.read(File.join(File.dirname(__FILE__), 'fixtures', 'test.json')) }
9
+ let(:output_path) { File.join(File.dirname(__FILE__), 'test_result', 'test.json') }
10
+ let(:output) { File.read(output_path) }
11
+ let(:options) { { } }
12
+
13
+ subject { WaveToJson.new(mp3_path, output_path, options).generate }
14
+
15
+ after { FileUtils.rm(output_path) }
16
+
17
+ it 'generates waveform in json format' do
18
+ subject
19
+ output_in_json = Oj.load(output)
20
+ expected_output_in_json = Oj.load(expected_output)
21
+
22
+ output_in_json.each_with_index do |value, index|
23
+ expected_value = expected_output_in_json[index]
24
+ value.should be_within(esp).of(expected_value)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "wave_to_json/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "wave_to_json"
7
+ s.version = WaveToJson::VERSION
8
+ s.authors = ["Sunjin Lee"]
9
+ s.email = ["styner32@gmail.com"]
10
+ s.homepage = "https://github.com/styner32/wave-to-json"
11
+ s.summary = %q{Convert audio file in json format}
12
+ s.description = %q{Convert audio file in json format}
13
+ s.license = 'MIT'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+
19
+ s.require_paths = ["lib"]
20
+ s.required_ruby_version = '>= 2.0.0'
21
+
22
+ s.add_runtime_dependency "oj", "~> 2.0"
23
+ s.add_runtime_dependency "thor", "~> 0.19"
24
+
25
+ s.add_development_dependency "rake"
26
+ s.add_development_dependency "rspec"
27
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wave_to_json
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sunjin Lee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oj
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.19'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.19'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Convert audio file in json format
70
+ email:
71
+ - styner32@gmail.com
72
+ executables:
73
+ - wave_to_json
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - Gemfile
80
+ - Gemfile.lock
81
+ - README.md
82
+ - Rakefile
83
+ - bin/wave_to_json
84
+ - c
85
+ - lib/wave_to_json.rb
86
+ - lib/wave_to_json/audio.rb
87
+ - lib/wave_to_json/cli.rb
88
+ - lib/wave_to_json/shell_command.rb
89
+ - lib/wave_to_json/version.rb
90
+ - spec/fixtures/test.json
91
+ - spec/fixtures/test.mp3
92
+ - spec/spec_helper.rb
93
+ - spec/test_result/.gitkeep
94
+ - spec/wave_to_json_spec.rb
95
+ - wave_to_json.gemspec
96
+ homepage: https://github.com/styner32/wave-to-json
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: 2.0.0
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.1.10
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Convert audio file in json format
120
+ test_files:
121
+ - spec/fixtures/test.json
122
+ - spec/fixtures/test.mp3
123
+ - spec/spec_helper.rb
124
+ - spec/test_result/.gitkeep
125
+ - spec/wave_to_json_spec.rb
126
+ has_rdoc: