audio_analysis 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/audio_analysis.rb +19 -0
- data/lib/bpm_analysis.py +14 -0
- data/lib/key_analysis.py +27 -0
- data/lib/requirements.txt +1 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4c59af24d399fb012742bd0643c1d9bfbe5a44dba189508bd879a820a50a3fc9
|
4
|
+
data.tar.gz: 0652d8f10711016ebac84822ae8bb2a123a44b676cdcba01bba5a6528e69f5fc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f52d7bdd8754d600567ac8b8c2a03e5b22e63c4e3b0a54670bc8fc97b5a35740dc54174c944a892950f17d62efd3d5ac3f7c541c6c711c158cbc782a56877245
|
7
|
+
data.tar.gz: ea0f0873f38c3f4bc710a038077fb9912f9f24d89654c04baf758306cdf213ad3950c060c375417e912635b1541ddfc5c0bf2ebe32d66bfc7f3ecd1be92a93e3
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class AudioAnalysis
|
2
|
+
def self.find_bpm(file_path)
|
3
|
+
`pip install -r requirements.txt`
|
4
|
+
bpm = `python3 bpm_analysis.py #{file_path}`
|
5
|
+
bpm.to_f
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.find_key(file_path)
|
9
|
+
`pip install -r requirements.txt`
|
10
|
+
`python3 key_analysis.py #{file_path}`
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.analyze(file_path)
|
14
|
+
`pip install -r requirements.txt`
|
15
|
+
bpm = `python3 bpm_analysis.py #{file_path}`
|
16
|
+
key =`python3 key_analysis.py #{file_path}`
|
17
|
+
{ bpm: bpm, key: key }
|
18
|
+
end
|
19
|
+
end
|
data/lib/bpm_analysis.py
ADDED
@@ -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='')
|
data/lib/key_analysis.py
ADDED
@@ -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
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: audio_analysis
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 'Indigo Tech Tutorials '
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Get the BPM and Key of any audio file
|
14
|
+
email: indigo@tech.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/audio_analysis.rb
|
20
|
+
- lib/bpm_analysis.py
|
21
|
+
- lib/key_analysis.py
|
22
|
+
- lib/requirements.txt
|
23
|
+
homepage: https://rubygems.org/gems/audio_analysis
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubygems_version: 3.5.6
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Get the BPM and Key of any audio file
|
46
|
+
test_files: []
|