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
ec0bb94e
Commit
ec0bb94e
authored
Jun 24, 2014
by
Leigh Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added spectral_features example
parent
3bd7f57b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
2 deletions
+39
-2
crossValidationTemplate.py
sources/crossValidationTemplate.py
+39
-2
No files found.
sources/crossValidationTemplate.py
View file @
ec0bb94e
...
@@ -9,6 +9,9 @@ from sklearn import cross_validation
...
@@ -9,6 +9,9 @@ from sklearn import cross_validation
from
sklearn.neighbors
import
KNeighborsClassifier
from
sklearn.neighbors
import
KNeighborsClassifier
from
sklearn
import
preprocessing
from
sklearn
import
preprocessing
import
urllib2
# the lib that handles the url stuff
import
urllib2
# the lib that handles the url stuff
import
urllib
from
essentia.standard
import
MonoLoader
from
essentia.standard
import
ZeroCrossingRate
,
CentralMoments
,
Spectrum
,
Windowing
,
Centroid
# Here are examples of how scaling functions would be written, however nowdays SciKit
# Here are examples of how scaling functions would be written, however nowdays SciKit
# Learn will do it for you with the MinMaxScaler!
# Learn will do it for you with the MinMaxScaler!
...
@@ -86,6 +89,7 @@ def crossValidateKNN(features, labels):
...
@@ -86,6 +89,7 @@ def crossValidateKNN(features, labels):
errors
[
foldIndex
]
=
matches
.
mean
()
errors
[
foldIndex
]
=
matches
.
mean
()
print
(
'cross validation error:
%
f'
%
errors
.
mean
())
print
(
'cross validation error:
%
f'
%
errors
.
mean
())
print
(
'cross validation accuracy:
%
f'
%
(
1.0
-
errors
.
mean
()))
print
(
'cross validation accuracy:
%
f'
%
(
1.0
-
errors
.
mean
()))
return
errors
def
process_corpus
(
corpusURL
):
def
process_corpus
(
corpusURL
):
...
@@ -96,6 +100,39 @@ def process_corpus(corpusURL):
...
@@ -96,6 +100,39 @@ def process_corpus(corpusURL):
yield
fileURL
.
rstrip
()
yield
fileURL
.
rstrip
()
# return [fileURL.rstrip() for fileURL in urlListTextData]
# return [fileURL.rstrip() for fileURL in urlListTextData]
# audioFileURLs = process
C
orpus("https://ccrma.stanford.edu/workshops/mir2014/SmallCorpus.txt")
# audioFileURLs = process
_c
orpus("https://ccrma.stanford.edu/workshops/mir2014/SmallCorpus.txt")
# for audioFileURL in process
C
orpus("https://ccrma.stanford.edu/workshops/mir2014/SmallCorpus.txt"):
# for audioFileURL in process
_c
orpus("https://ccrma.stanford.edu/workshops/mir2014/SmallCorpus.txt"):
# print audioFileURL
# print audioFileURL
def
spectral_features
(
filelist
):
"""
Given a list of files, retrieve them, analyse the first 100mS of each file and return
a feature table.
"""
number_of_files
=
len
(
filelist
)
number_of_features
=
5
features
=
np
.
zeros
([
number_of_files
,
number_of_features
])
sample_rate
=
44100
for
file_index
,
url
in
enumerate
(
filelist
):
print
url
urllib
.
urlretrieve
(
url
,
filename
=
'/tmp/localfile.wav'
)
audio
=
MonoLoader
(
filename
=
'/tmp/localfile.wav'
,
sampleRate
=
sample_rate
)()
zcr
=
ZeroCrossingRate
()
hamming_window
=
Windowing
(
type
=
'hamming'
)
# we need to window the frame to avoid FFT artifacts.
spectrum
=
Spectrum
()
central_moments
=
CentralMoments
()
spectral_centroid
=
Centroid
()
frame_size
=
int
(
round
(
0.100
*
sample_rate
))
# 100ms
# Only do the first frame for now.
# TODO we should generate values for the entire file, probably by averaging the features.
current_frame
=
audio
[
0
:
frame_size
]
features
[
file_index
,
0
]
=
zcr
(
current_frame
)
spectral_magnitude
=
spectrum
(
hamming_window
(
current_frame
))
centroid
=
spectral_centroid
(
spectral_magnitude
)
spectral_moments
=
central_moments
(
spectral_magnitude
)
features
[
file_index
,
1
]
=
centroid
features
[
file_index
,
2
:
5
]
=
spectral_moments
[
2
:
5
]
return
features
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