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 @@
1#! /usr/bin/env python1#! /usr/bin/env python
2 2
3import os3import os
4import re
4import glob5import glob
5import numpy as np6import numpy as np
6from tempfile import mkstemp7from tempfile import mkstemp
@@ -77,3 +78,16 @@ def count_files_in_directory(samples_dir): · 70 unmodified lines
77 if file_path:78 if file_path:
78 total_files += 179 total_files += 1
79 return total_files80 return total_files
81
82def 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