6 from tempfile import mkstemp
8 DEFAULT_SOUND = '22050Hz_5s_brownnoise.wav'
10 def array_from_text_file(filename, dtype = 'float'):
11 realpathname = os.path.join(os.path.dirname(__file__), filename)
12 return np.loadtxt(realpathname, dtype = dtype)
14 def list_all_sounds(rel_dir):
15 datadir = os.path.join(os.path.dirname(__file__), rel_dir)
16 return glob.glob(os.path.join(datadir,'*.*'))
18 def get_default_test_sound(TestCase, rel_dir = 'sounds'):
19 all_sounds = list_all_sounds(rel_dir)
20 if len(all_sounds) == 0:
21 TestCase.skipTest("please add some sounds in \'python/tests/sounds\'")
23 default_sound = all_sounds[0]
24 if DEFAULT_SOUND in map(os.path.basename, all_sounds):
25 while os.path.basename(default_sound) != DEFAULT_SOUND:
26 default_sound = all_sounds.pop(0)
29 def get_tmp_sink_path():
34 def del_tmp_sink_path(path):
37 except WindowsError as e:
38 # removing the temporary directory sometimes fails on windows
40 errmsg = "failed deleting temporary file {:s} ({:s})"
41 warnings.warn(UserWarning(errmsg.format(path, repr(e))))
43 def array_from_yaml_file(filename):
46 yaml_data = yaml.safe_load(f)
50 def count_samples_in_file(file_path):
51 from aubio import source
53 s = source(file_path, 0, hopsize)
58 if read < hopsize: break
61 def count_samples_in_directory(samples_dir):
63 for f in os.walk(samples_dir):
66 file_path = os.path.join(f[0], each)
68 total_frames += count_samples_in_file(file_path)
71 def count_files_in_directory(samples_dir):
73 for f in os.walk(samples_dir):
76 file_path = os.path.join(f[0], each)