#! /usr/bin/env python
import os
+import re
import glob
import numpy as np
from tempfile import mkstemp
try:
os.unlink(path)
except WindowsError as e:
- print("deleting {:s} failed ({:s}), reopening".format(path, repr(e)))
- with open(path, 'wb') as f:
- f.close()
- try:
- os.unlink(path)
- except WindowsError as f:
- print("deleting {:s} failed ({:s}), aborting".format(path, repr(e)))
+ # removing the temporary directory sometimes fails on windows
+ import warnings
+ errmsg = "failed deleting temporary file {:s} ({:s})"
+ warnings.warn(UserWarning(errmsg.format(path, repr(e))))
def array_from_yaml_file(filename):
import yaml
if file_path:
total_files += 1
return total_files
+
+def parse_file_samplerate(soundfile):
+ samplerate = None
+ # parse samplerate
+ re_sr = re.compile(r'/([0-9]{4,})Hz_.*')
+ match_samplerate = re_sr.findall(soundfile)
+ if match_samplerate:
+ samplerate = int(match_samplerate[0])
+ else:
+ import warnings
+ warnings.warn(UserWarning("could not parse samplerate for {:s}"
+ .format(soundfile)))
+ return samplerate