shithub: aubio

Download patch

ref: cd4689242b0192990ef21faf1301fe2d95504325
parent: 966c65065c439fbc725650df96603086f346530d
author: Paul Brossier <piem@piem.org>
date: Sun Dec 23 00:48:12 EST 2018

[tests] add parse_file_samplerate to fetch samplerate from path

--- 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 @@
                 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