Changeset f264b17 for python/tests/utils.py
- Timestamp:
- Jun 22, 2016, 1:00:10 PM (9 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 4b9443c4
- Parents:
- 60fc05b (diff), 6769586 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/tests/utils.py
r60fc05b rf264b17 1 1 #! /usr/bin/env python 2 2 3 import os 4 import glob 5 import numpy as np 6 from tempfile import mkstemp 7 3 8 def array_from_text_file(filename, dtype = 'float'): 4 import os.path5 from numpy import array6 9 filename = os.path.join(os.path.dirname(__file__), filename) 7 return array([line.split() for line in open(filename).readlines()], 8 dtype = dtype) 10 with open(filename) as f: 11 lines = f.readlines() 12 return np.array([line.split() for line in lines], 13 dtype = dtype) 9 14 10 15 def list_all_sounds(rel_dir): 11 import os.path, glob12 16 datadir = os.path.join(os.path.dirname(__file__), rel_dir) 13 17 return glob.glob(os.path.join(datadir,'*.*')) … … 21 25 22 26 def get_tmp_sink_path(): 23 from tempfile import mkstemp24 import os25 27 fd, path = mkstemp() 26 28 os.close(fd) … … 28 30 29 31 def del_tmp_sink_path(path): 30 import os 31 os.unlink(path) 32 try: 33 os.unlink(path) 34 except WindowsError as e: 35 print("deleting {:s} failed ({:s}), reopening".format(path, repr(e))) 36 with open(path, 'wb') as f: 37 f.close() 38 try: 39 os.unlink(path) 40 except WindowsError as f: 41 print("deleting {:s} failed ({:s}), aborting".format(path, repr(e))) 32 42 33 43 def array_from_yaml_file(filename): … … 44 54 total_frames = 0 45 55 while True: 46 samples, read = s()56 _, read = s() 47 57 total_frames += read 48 58 if read < hopsize: break … … 50 60 51 61 def count_samples_in_directory(samples_dir): 52 import os53 62 total_frames = 0 54 63 for f in os.walk(samples_dir): … … 61 70 62 71 def count_files_in_directory(samples_dir): 63 import os64 72 total_files = 0 65 73 for f in os.walk(samples_dir):
Note: See TracChangeset
for help on using the changeset viewer.