Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
musicinformationretrieval-com
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
A.S.
musicinformationretrieval-com
Commits
a7f5c412
Commit
a7f5c412
authored
Mar 18, 2018
by
Steve Tjoa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stanford_mir.init()
parent
15c3d2b2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
stanford_mir.py
stanford_mir.py
+22
-6
No files found.
stanford_mir.py
View file @
a7f5c412
import
errno
import
librosa
import
matplotlib
,
matplotlib
.
pyplot
as
plt
import
numpy
import
os
import
os.path
import
sklearn
import
urllib
import
urllib.request
def
init
():
plt
.
style
.
use
(
'seaborn-muted'
)
#plt.rcParams['figure.figsize'] = (14, 5)
plt
.
rcParams
[
'axes.grid'
]
=
True
plt
.
rcParams
[
'axes.spines.left'
]
=
False
plt
.
rcParams
[
'axes.spines.right'
]
=
False
plt
.
rcParams
[
'axes.spines.bottom'
]
=
False
plt
.
rcParams
[
'axes.spines.top'
]
=
False
plt
.
rcParams
[
'axes.xmargin'
]
=
0
plt
.
rcParams
[
'axes.ymargin'
]
=
0
plt
.
rcParams
[
'image.cmap'
]
=
'gray'
plt
.
rcParams
[
'image.interpolation'
]
=
None
def
extract_features
(
signal
,
features
):
fvs
=
list
()
...
...
@@ -15,6 +30,7 @@ def extract_features(signal, features):
fvs
.
append
(
librosa
.
feature
.
spectral_centroid
(
signal
)[
0
,
0
]
)
return
fvs
def
get_features
(
collection
=
'drum_samples_train'
,
features
=
(
'zero_crossing_rate'
,
'spectral_centroid'
),
scaler
=
None
,
...
...
@@ -88,7 +104,7 @@ def download_samples(collection='drum_samples_train', download=True):
for
drum_type
in
[
'kick'
,
'snare'
]:
for
i
in
range
(
1
,
11
):
filename
=
'
%
s_
%02
d.wav'
%
(
drum_type
,
i
)
urllib
.
urlretrieve
(
'http://audio.musicinformationretrieval.com/drum_samples/
%
s'
%
filename
,
urllib
.
request
.
urlretrieve
(
'http://audio.musicinformationretrieval.com/drum_samples/
%
s'
%
filename
,
filename
=
os
.
path
.
join
(
collection
,
filename
))
kick_filepaths
=
[
os
.
path
.
join
(
collection
,
'kick_
%02
d.wav'
%
i
)
for
i
in
range
(
1
,
11
)]
snare_filepaths
=
[
os
.
path
.
join
(
collection
,
'snare_
%02
d.wav'
%
i
)
for
i
in
range
(
1
,
11
)]
...
...
@@ -99,19 +115,19 @@ def download_samples(collection='drum_samples_train', download=True):
for
drum_type
in
[
'kick'
,
'snare'
]:
for
i
in
range
(
30
):
filename
=
'
%
s_
%02
d.wav'
%
(
drum_type
,
i
)
urllib
.
urlretrieve
(
'http://audio.musicinformationretrieval.com/drum_samples/test/
%
s'
%
filename
,
urllib
.
request
.
urlretrieve
(
'http://audio.musicinformationretrieval.com/drum_samples/test/
%
s'
%
filename
,
filename
=
os
.
path
.
join
(
collection
,
filename
))
kick_filepaths
=
[
os
.
path
.
join
(
collection
,
'kick_
%02
d.wav'
%
i
)
for
i
in
range
(
30
)]
snare_filepaths
=
[
os
.
path
.
join
(
collection
,
'snare_
%02
d.wav'
%
i
)
for
i
in
range
(
30
)]
return
kick_filepaths
,
snare_filepaths
elif
collection
==
'violin_samples_train'
:
urllib
.
urlretrieve
(
'http://audio.musicinformationretrieval.com/violin_samples_train/list.txt'
,
urllib
.
request
.
urlretrieve
(
'http://audio.musicinformationretrieval.com/violin_samples_train/list.txt'
,
filename
=
os
.
path
.
join
(
collection
,
'list.txt'
))
for
line
in
open
(
os
.
path
.
join
(
collection
,
'list.txt'
),
'r'
):
filename
=
line
.
strip
()
print
filename
print
(
filename
)
if
filename
.
endswith
(
'.wav'
):
urllib
.
urlretrieve
(
'http://audio.musicinformationretrieval.com/'
+
filename
,
urllib
.
request
.
urlretrieve
(
'http://audio.musicinformationretrieval.com/'
+
filename
,
filename
=
filename
)
return
[
os
.
path
.
join
(
collection
,
f
)
for
f
in
os
.
listdir
(
collection
)]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment