History

[tests] add parse_file_samplerate to fetch samplerate from path

Paul Brossier committed 7 years ago

Commit cd468921 parent 966c6501 file · +14 −0Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/tests/utils.py+14−0
@@ -1,6 +1,7 @@
11 #! /usr/bin/env python
22
33 import os
4+import re
45 import glob
56 import numpy as np
67 from tempfile import mkstemp
@@ -77,3 +78,16 @@ def count_files_in_directory(samples_dir): · 70 unmodified lines
7778 if file_path:
7879 total_files += 1
7980 return total_files
81+
82+def parse_file_samplerate(soundfile):
83+ samplerate = None
84+ # parse samplerate
85+ re_sr = re.compile(r'/([0-9]{4,})Hz_.*')
86+ match_samplerate = re_sr.findall(soundfile)
87+ if match_samplerate:
88+ samplerate = int(match_samplerate[0])
89+ else:
90+ import warnings
91+ warnings.warn(UserWarning("could not parse samplerate for {:s}"
92+ .format(soundfile)))
93+ return samplerate

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t