-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlabel_audio_data.py
50 lines (40 loc) · 1.17 KB
/
label_audio_data.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
import os.path as osp
import numpy as np
import torch
from torch_audioset.engine import classify_audio_dataset
# create a dummy dataset
class DummyDset(torch.utils.data.Dataset):
def __init__(self):
self.size = 100
@staticmethod
def get_data():
num_secs = 1.5 * 60 * 60
freq = 1000
sample_rate = 44100
t = np.linspace(0, num_secs, int(num_secs * sample_rate))
x = np.sin(2 * np.pi * freq * t)
# float32, [C=2, T=num_secs * sr]
x = x.astype(np.float32).reshape(1, -1)
return x, sample_rate
def __len__(self):
return self.size
def __getitem__(self, index):
x, sr = self.get_data()
x = torch.from_numpy(x).float()
return {
'id': str(index),
'data': x, 'sr': sr,
'meta': {
'secret': 'top-secret'
}
}
def main():
# create output dir
this_file_dir = osp.abspath(osp.dirname(__file__))
output_dir = osp.join(this_file_dir, 'output')
os.makedirs(output_dir, exist_ok=True)
dset = DummyDset()
classify_audio_dataset(dset, output_dir)
if __name__ == "__main__":
main()