-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathDatasets.py
31 lines (22 loc) · 1012 Bytes
/
Datasets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os.path
from Sample import Sample
from lxml import etree
def create_sample(db_path, noise_node):
path = db_path + os.path.sep + noise_node.xpath("./relativeFilepath")[0].text
sample_rate = int(noise_node.xpath("./sampleRate")[0].text)
channels = int(noise_node.xpath("./numChannels")[0].text)
duration = float(noise_node.xpath("./length")[0].text)
return Sample(path, sample_rate, channels, duration)
def getAudioData(xml_path):
tree = etree.parse(xml_path)
root = tree.getroot()
db_path = root.find("./databaseFolderPath").text
tracks = root.findall(".//track")
samples = list()
for track in tracks:
# Get mix and sources
speech = create_sample(db_path, track.xpath(".//source[sourceName='Speech']")[0])
mix = create_sample(db_path, track.xpath(".//source[sourceName='Mix']")[0])
noise = create_sample(db_path, track.xpath(".//source[sourceName='Noise']")[0])
samples.append((mix, noise, speech))
return samples