6 from tempfile import mkstemp
8 DEFAULT_SOUND = '22050Hz_5s_brownnoise.wav'
10 def array_from_text_file(filename, dtype = 'float'):
11 filename = os.path.join(os.path.dirname(__file__), filename)
12 with open(filename) as f:
14 return np.array([line.split() for line in lines],
17 def list_all_sounds(rel_dir):
18 datadir = os.path.join(os.path.dirname(__file__), rel_dir)
19 return glob.glob(os.path.join(datadir,'*.*'))
21 def get_default_test_sound(TestCase, rel_dir = 'sounds'):
22 all_sounds = list_all_sounds(rel_dir)
23 if len(all_sounds) == 0:
24 TestCase.skipTest("please add some sounds in \'python/tests/sounds\'")
26 default_sound = all_sounds[0]
27 if DEFAULT_SOUND in map(os.path.basename, all_sounds):
28 while os.path.basename(default_sound) != DEFAULT_SOUND:
29 default_sound = all_sounds.pop(0)
32 def get_tmp_sink_path():
37 def del_tmp_sink_path(path):
40 except WindowsError as e:
41 print("deleting {:s} failed ({:s}), reopening".format(path, repr(e)))
42 with open(path, 'wb') as f:
46 except WindowsError as f:
47 print("deleting {:s} failed ({:s}), aborting".format(path, repr(e)))
49 def array_from_yaml_file(filename):
52 yaml_data = yaml.safe_load(f)
56 def count_samples_in_file(file_path):
57 from aubio import source
59 s = source(file_path, 0, hopsize)
64 if read < hopsize: break
67 def count_samples_in_directory(samples_dir):
69 for f in os.walk(samples_dir):
72 file_path = os.path.join(f[0], each)
74 total_frames += count_samples_in_file(file_path)
77 def count_files_in_directory(samples_dir):
79 for f in os.walk(samples_dir):
82 file_path = os.path.join(f[0], each)