6
6
import multiprocessing
7
7
import pprint
8
8
import csv
9
- import new_filter_function
10
9
import threading
11
10
import googleapiclient
12
11
from collections import Counter
@@ -127,10 +126,10 @@ def text_to_num(num, source_name="", results_dict={}):
127
126
def sphinx (audio , vals , i , results_dict , timing ):
128
127
try :
129
128
#print("Sphinx: ")
130
- s = time .time ()
129
+ s = time .time ()
131
130
vals [i ] = text_to_num (r .recognize_sphinx (audio ), "sphinx" , results_dict )
132
- timing ["sphinx" ].append (time .time () - s )
133
- print "timing2" , timing
131
+ timing ["sphinx" ].append (time .time () - s )
132
+ print "timing2" , timing
134
133
except sr .UnknownValueError :
135
134
logging .debug ("Sphinx could not understand audio" )
136
135
results_dict ["sphinx" ] = [DEFAULT ]
@@ -156,12 +155,13 @@ def googleCloud(audio, vals, i, results_dict, timing):
156
155
}"""
157
156
try :
158
157
s = time .time ()
159
- #print("Google Cloud Speech: ")
158
+ #print("Google Cloud Speech: ")
160
159
vals [i ] = text_to_num (r .recognize_google_cloud (audio , \
161
- preferred_phrases = ["zero" , "one" , "two" , "three" , "four" , "five" , "six" , "seven" , "eight" , "nine" ],\
162
- credentials_json = GOOGLE_CLOUD_SPEECH_CREDENTIALS ), "googleCloud" , results_dict )
163
- timing ["googleCloud" ].append (time .time () - s )
164
- print "timing" , timing ["googleCloud" ]
160
+ preferred_phrases = ["zero" , "one" , "two" , "three" , "four" , "five" , "six" , "seven" , "eight" , "nine" ],\
161
+ credentials_json = GOOGLE_CLOUD_SPEECH_CREDENTIALS ), "googleCloud" , results_dict )
162
+
163
+ timing ["googleCloud" ].append (time .time () - s )
164
+ print "timing" , timing ["googleCloud" ]
165
165
#print("Google Cloud " + str(vals[i]))
166
166
except sr .UnknownValueError :
167
167
logging .debug ("Google Cloud Speech could not understand audio" )
@@ -171,17 +171,17 @@ def googleCloud(audio, vals, i, results_dict, timing):
171
171
logging .debug ("Could not request results from Google Cloud Speech service; {0}" .format (e ))
172
172
results_dict ["googleCloud" ] = [DEFAULT ]
173
173
results_dict ["googleCloud_fil" ] = [DEFAULT ]
174
- except :
175
- pass
174
+ except :
175
+ pass
176
176
#Query Wit
177
177
def wit (audio , vals , i , results_dict , timing ):
178
178
# recognize speech using Wit.ai
179
179
WIT_AI_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx" # Wit.ai keys are 32-character uppercase alphanumeric strings
180
180
try :
181
- s = time .time ()
181
+ s = time .time ()
182
182
#print("Wit.ai: ")
183
183
vals [i ] = text_to_num (r .recognize_wit (audio , key = WIT_AI_KEY ), "wit" , results_dict )
184
- timing ["wit" ].append (time .time () - s )
184
+ timing ["wit" ].append (time .time () - s )
185
185
#print("Wit " + str(vals[i]))
186
186
except sr .UnknownValueError :
187
187
logging .debug ("Wit.ai could not understand audio" )
@@ -198,10 +198,10 @@ def bing(audio, vals, i, results_dict, timing):
198
198
199
199
BING_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
200
200
try :
201
- s = time .time ()
201
+ s = time .time ()
202
202
#print("Microsoft Bing Voice Recognition: ")
203
203
vals [i ] = text_to_num (r .recognize_bing (audio , key = BING_KEY ), "bing" , results_dict )
204
- timing ["bing" ].append (time .time () - s )
204
+ timing ["bing" ].append (time .time () - s )
205
205
except sr .UnknownValueError :
206
206
logging .debug ("Microsoft Bing Voice Recognition could not understand audio" )
207
207
results_dict ["bing" ] = [DEFAULT ]
@@ -216,11 +216,11 @@ def ibm(audio, vals, i, results_dict, timing, show_all=False):
216
216
IBM_USERNAME = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" # IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
217
217
IBM_PASSWORD = "XXXXXXXXXX" # IBM Speech to Text passwords are mixed-case alphanumeric strings
218
218
try :
219
- s = time .time ()
219
+ s = time .time ()
220
220
#print("IBM Speech to Text: ")
221
221
vals [i ] = text_to_num (r .recognize_ibm (audio , username = IBM_USERNAME , \
222
- password = IBM_PASSWORD , show_all = False ), "ibm" , results_dict )
223
- timing ["ibm" ].append (time .time () - s )
222
+ password = IBM_PASSWORD , show_all = False ), "ibm" , results_dict )
223
+ timing ["ibm" ].append (time .time () - s )
224
224
except sr .UnknownValueError :
225
225
logging .debug ("IBM Speech to Text could not understand audio" )
226
226
results_dict ["ibm" ] = [DEFAULT ]
@@ -233,9 +233,9 @@ def ibm(audio, vals, i, results_dict, timing, show_all=False):
233
233
def google (audio , vals , i , results_dict , timing ):
234
234
try :
235
235
#print("Google: ")
236
- s = time .time ()
236
+ s = time .time ()
237
237
vals [i ] = text_to_num (r .recognize_google (audio ), "google" , results_dict )
238
- timing ["google" ].append (time .time () - s )
238
+ timing ["google" ].append (time .time () - s )
239
239
except :
240
240
logging .debug ("Google could not understand" )
241
241
results_dict ["google" ] = [DEFAULT ]
@@ -365,9 +365,9 @@ def getNum(audio_file, results_dict, digit_num=0, ans=[]):
365
365
results_dict_threaded = manage_vars .dict ()
366
366
results = []
367
367
threads = []
368
- timed = manage_vars .dict ()
369
- for api in apis :
370
- timed [api ] = manage_vars .list ()
368
+ timed = manage_vars .dict ()
369
+ for api in apis :
370
+ timed [api ] = manage_vars .list ()
371
371
apis_func = [googleCloud , sphinx , wit , bing , google , ibm ]
372
372
i = 0
373
373
start = time .time ()
@@ -379,7 +379,7 @@ def getNum(audio_file, results_dict, digit_num=0, ans=[]):
379
379
380
380
for thread in threads :
381
381
thread .join ()
382
- end = time .time ()
382
+ end = time .time ()
383
383
print "getnumtime" , end - start
384
384
print timed
385
385
results_dict ["time" + str (digit_num )] = end - start
@@ -404,14 +404,14 @@ def getNum(audio_file, results_dict, digit_num=0, ans=[]):
404
404
results = sorted (results , key = results .count , reverse = True )
405
405
if not results :
406
406
logging .debug ("FOUND NOTHING" )
407
- ans [digit_num ] = DEFAULT
407
+ ans [digit_num ] = DEFAULT
408
408
return DEFAULT
409
409
else :
410
410
# print(results[0])
411
411
logging .info ("DETERMINED AS: " + str (results [0 ]))
412
- print ans
413
- print digit_num
414
- ans [digit_num ] = results [0 ]
412
+ print ans
413
+ print digit_num
414
+ ans [digit_num ] = results [0 ]
415
415
return results [0 ]
416
416
417
417
def test_dir (directory ):
0 commit comments