From: Paul Brossier Date: Sun, 23 Dec 2018 04:48:12 +0000 (+0100) Subject: [tests] add parse_file_samplerate to fetch samplerate from path X-Git-Tag: 0.4.9~14 X-Git-Url: https://git.aubio.org/?p=aubio.git;a=commitdiff_plain;h=cd4689242b0192990ef21faf1301fe2d95504325 [tests] add parse_file_samplerate to fetch samplerate from path --- diff --git a/python/tests/utils.py b/python/tests/utils.py index 5b789eaa..4b414883 100644 --- a/python/tests/utils.py +++ b/python/tests/utils.py @@ -1,6 +1,7 @@ #! /usr/bin/env python import os +import re import glob import numpy as np from tempfile import mkstemp @@ -77,3 +78,16 @@ def count_files_in_directory(samples_dir): 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