#! /usr/bin/env python
import os
+import re
import glob
+import struct
import numpy as np
from tempfile import mkstemp
DEFAULT_SOUND = '22050Hz_5s_brownnoise.wav'
+def is32bit():
+ return struct.calcsize("P") * 8 == 32
+
def array_from_text_file(filename, dtype = 'float'):
realpathname = os.path.join(os.path.dirname(__file__), filename)
return np.loadtxt(realpathname, dtype = dtype)
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