@@ -137,44 +137,48 @@ def reconize_with_model(filename,model,username):
137
137
#modelpath = "./temp/models/"
138
138
139
139
140
- gmm_files = [os .path .join (modelpath ,fname ) for fname in
141
- os .listdir (modelpath ) if fname .endswith ('.gmm' )]
140
+ # gmm_files = [os.path.join(modelpath,fname) for fname in
141
+ # os.listdir(modelpath) if fname.endswith('.gmm')]
142
142
143
- models = [ pickle .load (open (fname ,'rb' )) for fname in gmm_files ]
143
+ models = pickle .load (open (modelpath ,'rb' ))
144
144
145
- speakers = [fname .split ("/" )[- 1 ].split (".gmm" )[0 ] for fname
146
- in gmm_files ]
145
+ # speakers = [fname.split("/")[-1].split(".gmm")[0] for fname
146
+ # in gmm_files]
147
147
148
- if len (models ) == 0 :
149
- print ("No Users in the Database!" )
150
- return
148
+ # if len(models) == 0:
149
+ # print("No Users in the Database!")
150
+ # return
151
151
152
152
#read test file
153
153
sr ,audio = read (FILENAME )
154
154
155
155
# extract mfcc features
156
156
vector = extract_features (audio ,sr )
157
- log_likelihood = np . zeros ( len ( models ))
157
+ log_likelihood = 0
158
158
159
159
#checking with each model one by one
160
160
#scorer = 0
161
- for i in range (len (models )):
162
- gmm = models [i ]
163
- scores = np .array (gmm .score (vector ))
164
- log_likelihood [i ] = scores .sum ()
165
- if speakers [i ] == username :
166
- scorer = log_likelihood [i ]
167
- print ("\n \n \n " )
168
- print (speakers [i ])
169
- print (log_likelihood [i ])
170
-
171
- pred = np .argmax (log_likelihood )
172
- identity = speakers [pred ]
173
- maximum = max (log_likelihood )
174
- minimum = min (log_likelihood )
175
-
176
- score = (2 * (scorer - minimum )/ (maximum - minimum )) - 1
161
+ #for i in range(len(models)):
162
+ gmm = models
163
+ scores = np .array (gmm .score (vector ))
164
+ log_likelihood = scores .sum ()/ len (scores )
165
+ #if speakers[i] == username:
166
+ #scorer = log_likelihood[i]
167
+ print ("\n \n \n " )
168
+ #print(speakers[i])
169
+ print (log_likelihood )
170
+
171
+ #pred = np.argmax(log_likelihood)
172
+ if log_likelihood > - 4 :
173
+ identity = username
174
+ else :
175
+ identity = "Unknown"
176
+ maximum = 0
177
+ minimum = - 30
178
+
179
+ score = (2 * (log_likelihood - minimum )/ (maximum - minimum )) - 1
177
180
#score = int(score)
181
+ #score = log_likelihood
178
182
179
183
180
184
# if voice not recognized than terminate the process
0 commit comments