audio_analysis 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/audio_analysis.rb +13 -7
- data/lib/python_analysis/bpm_analysis.py +14 -0
- data/lib/python_analysis/key_analysis.py +27 -0
- data/lib/python_analysis/requirements.txt +1 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29e393fe23792ab42e8be688b502b74ac6302b9bed789d38de45c3b9fef00ba1
|
4
|
+
data.tar.gz: 4b1ddf61484442ad4e5e2a5f40c841b64710d1d5a1cd7a6fe7b80da7cd744edc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8ad08d3049aa0a33e6c93d0c425ae486aa947fd9e2bc118bdba7ce5abfaa64b8b88627f8e72a52cb8e53bb10f779bbaea137ecb7911cd6fb4e57c4c48aa60ae
|
7
|
+
data.tar.gz: 6a4f9904f2187aad58cae81e5134c5fc7a3fbb6b58bde93c976900ef9913369bd1bd65910fb417fa6bf4df472b50414309a119e889b5490f2dcca4360c6cf198
|
data/lib/audio_analysis.rb
CHANGED
@@ -1,19 +1,25 @@
|
|
1
1
|
class AudioAnalysis
|
2
2
|
def self.find_bpm(file_path)
|
3
|
-
`pip install -r lib/python_analysis/requirements.txt`
|
4
|
-
bpm = `python3 lib/python_analysis/bpm_analysis.py #{file_path}`
|
3
|
+
`pip install -r #{gem_path}/lib/python_analysis/requirements.txt`
|
4
|
+
bpm = `python3 #{gem_path}/lib/python_analysis/bpm_analysis.py #{file_path}`
|
5
5
|
bpm.to_f
|
6
6
|
end
|
7
7
|
|
8
8
|
def self.find_key(file_path)
|
9
|
-
`pip install -r lib/python_analysis/requirements.txt`
|
10
|
-
`python3 lib/python_analysis/key_analysis.py #{file_path}`
|
9
|
+
`pip install -r #{gem_path}/lib/python_analysis/requirements.txt`
|
10
|
+
`python3 #{gem_path}/lib/python_analysis/key_analysis.py #{file_path}`
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.analyze(file_path)
|
14
|
-
`pip install -r lib/python_analysis/requirements.txt`
|
15
|
-
bpm = `python3 lib/python_analysis/bpm_analysis.py #{file_path}`
|
16
|
-
key =`python3 lib/python_analysis/key_analysis.py #{file_path}`
|
14
|
+
`pip install -r #{gem_path}/lib/python_analysis/requirements.txt`
|
15
|
+
bpm = `python3 #{gem_path}/lib/python_analysis/bpm_analysis.py #{file_path}`
|
16
|
+
key =`python3 #{gem_path}/lib/python_analysis/key_analysis.py #{file_path}`
|
17
17
|
{ bpm: bpm, key: key }
|
18
18
|
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def self.gem_path
|
23
|
+
Gem.loaded_specs["audio_analysis"].gem_dir
|
24
|
+
end
|
19
25
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import librosa
|
2
|
+
import sys
|
3
|
+
|
4
|
+
if len(sys.argv) != 2:
|
5
|
+
print("You have to pass in a file path `python3 analysis.py path_to_file.mp3`")
|
6
|
+
sys.exit(1)
|
7
|
+
|
8
|
+
audio_file = sys.argv[1]
|
9
|
+
y, sr = librosa.load(audio_file)
|
10
|
+
|
11
|
+
# Estimate tempo (BPM)
|
12
|
+
tempo, _ = librosa.beat.beat_track(y=y, sr=sr)
|
13
|
+
|
14
|
+
print(tempo, end='')
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import librosa
|
2
|
+
import numpy as np
|
3
|
+
import sys
|
4
|
+
|
5
|
+
if len(sys.argv) != 2:
|
6
|
+
print("You have to pass in a file path `python3 analysis.py path_to_file.mp3`")
|
7
|
+
sys.exit(1)
|
8
|
+
|
9
|
+
audio_file = sys.argv[1]
|
10
|
+
|
11
|
+
y, sr = librosa.load(audio_file)
|
12
|
+
|
13
|
+
# Compute the Chroma Short-Time Fourier Transform (chroma_stft)
|
14
|
+
chromagram = librosa.feature.chroma_stft(y=y, sr=sr)
|
15
|
+
|
16
|
+
# Calculate the mean chroma feature across time
|
17
|
+
mean_chroma = np.mean(chromagram, axis=1)
|
18
|
+
|
19
|
+
# Define the mapping of chroma features to keys
|
20
|
+
chroma_to_key = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#', 'A', 'A#', 'B']
|
21
|
+
|
22
|
+
# Find the key by selecting the maximum chroma feature
|
23
|
+
estimated_key_index = np.argmax(mean_chroma)
|
24
|
+
estimated_key = chroma_to_key[estimated_key_index]
|
25
|
+
|
26
|
+
# Print the detected key
|
27
|
+
print(estimated_key, end='')
|
@@ -0,0 +1 @@
|
|
1
|
+
librosa==0.10.1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: audio_analysis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 'Indigo Tech Tutorials '
|
@@ -17,10 +17,14 @@ extensions: []
|
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
19
|
- lib/audio_analysis.rb
|
20
|
+
- lib/python_analysis/bpm_analysis.py
|
21
|
+
- lib/python_analysis/key_analysis.py
|
22
|
+
- lib/python_analysis/requirements.txt
|
20
23
|
homepage: https://rubygems.org/gems/audio_analysis
|
21
24
|
licenses:
|
22
25
|
- MIT
|
23
|
-
metadata:
|
26
|
+
metadata:
|
27
|
+
source_code_uri: https://github.com/enochtamulonis/audio-analysis-gem
|
24
28
|
post_install_message:
|
25
29
|
rdoc_options: []
|
26
30
|
require_paths:
|