This repository has been archived by the owner on Feb 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlearn.py
52 lines (44 loc) · 1.53 KB
/
learn.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import scipy.io.wavfile as wav
import librosa
from sklearn.svm import SVC
import numpy
def getMfcc(filename):
y, sr = librosa.load(filename)
return librosa.feature.mfcc(y=y, sr=sr)
artists = ['HONOKA', 'ELI', 'KOTORI', 'UMI', 'RIN', 'MAKI', 'NOZOMI', 'HANAYO', 'NICO']
songs = [
'もぎゅっとloveで接近中-short',
'愛してるばんざーい',
'Wonderful-Rush',
'Oh-Love-and-Peace',
'僕らは今のなかで',
'WILD-STARS',
'きっと青春が聞こえる',
'輝夜の城で踊りたい',
'Wonder-zone',
'START-DASH'
]
song_training = []
artist_training = []
for artist in artists:
print('Reading data of %s...' % artist)
for song in songs:
mfcc = getMfcc('%s/%s-voice.wav' % (artist, song))
song_training.append(mfcc.T)
label = numpy.full((mfcc.shape[1], ), artists.index(artist), dtype=numpy.int)
artist_training.append(label)
song_training = numpy.concatenate(song_training)
artist_training = numpy.concatenate(artist_training)
clf = SVC(C=1, gamma=1e-4)
clf.fit(song_training, artist_training)
print('Learning Done')
counts = []
for artist in artists:
mfcc = getMfcc('%s/No-brand-girls-voice.wav' % artist)
prediction = clf.predict(mfcc.T)
counts.append(numpy.bincount(prediction))
counts = numpy.vstack(counts)
for artist, count in zip(artists, counts):
result = artists[numpy.argmax( count - count.mean(axis=0) )]
original_title = 'No brand girls(%s Mix)' % artist
print('%s recognized as sung by %s.' % (original_title, result))