21 from os.path
import dirname, join
22 from speech_recognition
import AudioSource
29 return "{0:.2f}".format(100.0 * val) +
"%" 36 UPDATE_INTERVAL_S = 1.0
39 self.
file = wave.open(file_name,
'rb')
40 self.
size = self.file.getnframes()
52 return float(self.file.tell()) / self.
size 54 def read(self, chunk_size):
61 cur_time = time.time()
67 return self.file.readframes(chunk_size)
94 ee = pyee.EventEmitter()
99 def on_found_wake_word():
100 SharedData.times_found += 1
102 ee.on(
'recognizer_loop:record_begin', on_found_wake_word)
106 self.listener.listen(source, ee)
110 return SharedData.times_found
121 return Color.BOLD + str(val) + Color.NORMAL
125 return dirname(dirname(__file__))
129 query = join(folder,
'*.wav')
131 full_path = join(root_dir, query)
132 file_names = sorted(glob(full_path))
134 if len(file_names) < 1:
142 for file_name
in file_names:
143 short_name = os.path.basename(file_name)
144 times_found = tester.test_audio(file_name)
146 num_found += times_found
147 on_file_finish(short_name, times_found)
153 wf = wave.open(file_name,
'rb')
154 frame_rate = wf.getframerate()
160 print(
"Wake word " +
bold_str(word) +
" - " + short_name)
169 def on_file_finish(short_name, times_found):
170 not_found_str = Color.RED +
"Not found" 171 found_str = Color.GREEN +
"Detected " 172 status_str = not_found_str
if times_found == 0
else found_str
176 total = len(file_names)
190 def on_file_finish(short_name, times_found):
191 not_found_str = Color.GREEN +
"Not found" 192 found_str = Color.RED +
"Detected " 193 status_str = not_found_str
if times_found == 0
else found_str
197 total = len(file_names)
200 print(
"Found " +
bold_str(num_found) +
" false positives")
201 print(
"in " +
bold_str(str(total)) +
" files")
206 directory = join(
'audio-accuracy-test',
'data')
208 false_neg_dir = join(directory,
'with_wake_word',
'query_after')
209 false_pos_dir = join(directory,
'without_wake_word')
214 print(
bold_str(
"Warning: No wav files found in " + false_neg_dir))
219 print(
bold_str(
"Warning: No wav files found in " + false_pos_dir))
224 if __name__ ==
"__main__":
def get_file_names(folder)
def test_audio_files(tester, file_names, on_file_finish)
def print_ww_found_status(word, short_name)
def test_audio(self, file_name)
def __init__(self, samp_rate)
def test_false_positive(directory)
def read(self, chunk_size)
def file_frame_rate(file_name)
def __init__(self, file_name)
def test_false_negative(directory)
def __init__(self, file_name)