-
Notifications
You must be signed in to change notification settings - Fork 2
/
SaveFingerprints.py
executable file
·52 lines (41 loc) · 1.21 KB
/
SaveFingerprints.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
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 10 21:53:11 2017
@author: wuyiming
"""
import numpy as np
import os
import sys
from librosa.util import find_files
from librosa.core import load
import analyze
import pickle
def hash_to_path(h):
h_str = "%05x" % h
directory = os.path.join("hashtable",h_str[:3])
if not os.path.exists(directory):
os.makedirs(directory)
return os.path.join(directory,h_str+".npz")
args = sys.argv
audiolist = find_files("/home/wuyiming/Projects/ChordData/Audio","wav")
hash_table = {}
title_list = []
audio_id = 0
for audiofile in audiolist:
print ("analyzing %03d: " % audio_id) + audiofile
y,sr = load(audiofile,sr=11025)
title_list.append(audiofile.split("/")[-1])
list_landmarks = analyze.extract_landmarks(y)
for landmark in list_landmarks:
hsh = landmark[0]
starttime = landmark[1]
if hash_table.has_key(hsh):
hash_table[hsh].append((audio_id,starttime))
else:
hash_table[hsh] = [(audio_id,starttime)]
audio_id += 1
print "Writing..."
with open("hashtable.pkl",mode="wb") as f:
pickle.dump(hash_table,f)
with open("titlelist.pkl",mode="wb") as f:
pickle.dump(title_list,f)