-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtest_speaker.py
49 lines (34 loc) · 1.28 KB
/
test_speaker.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
#test_gender.py
import os
import cPickle
import numpy as np
from scipy.io.wavfile import read
from speakerfeatures import extract_features
import warnings
warnings.filterwarnings("ignore")
import time
#path to training data
source = "development_set\\"
modelpath = "speaker_models\\"
test_file = "development_set_test.txt"
file_paths = open(test_file,'r')
gmm_files = [os.path.join(modelpath,fname) for fname in
os.listdir(modelpath) if fname.endswith('.gmm')]
#Load the Gaussian gender Models
models = [cPickle.load(open(fname,'r')) for fname in gmm_files]
speakers = [fname.split("\\")[-1].split(".gmm")[0] for fname
in gmm_files]
# Read the test directory and get the list of test audio files
for path in file_paths:
path = path.strip()
print path
sr,audio = read(source + path)
vector = extract_features(audio,sr)
log_likelihood = np.zeros(len(models))
for i in range(len(models)):
gmm = models[i] #checking with each model one by one
scores = np.array(gmm.score(vector))
log_likelihood[i] = scores.sum()
winner = np.argmax(log_likelihood)
print "\tdetected as - ", speakers[winner]
time.sleep(1.0)