Spaces:
Sleeping
Sleeping
NikitaSrivatsan
commited on
Commit
•
7b39cbc
1
Parent(s):
8971856
Removed pickling of input files
Browse files- data_module.py +24 -31
data_module.py
CHANGED
@@ -223,38 +223,31 @@ class AudiostockDataset(Dataset):
|
|
223 |
return tokens, mask, tweet_text_len
|
224 |
|
225 |
def read_wav(self, filename):
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
if self.train:
|
243 |
-
sta = random.randint(0, num_frames - 441001)
|
244 |
-
else:
|
245 |
-
sta = (num_frames - 441001) // 2
|
246 |
-
num_frames = 441000
|
247 |
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
# save
|
257 |
-
torch.save(y, picklepath)
|
258 |
return y
|
259 |
|
260 |
def __getitem__(self, index):
|
|
|
223 |
return tokens, mask, tweet_text_len
|
224 |
|
225 |
def read_wav(self, filename):
|
226 |
+
# pickling functionality removed since it shouldn't be necessary
|
227 |
+
# chunk
|
228 |
+
try:
|
229 |
+
num_frames = torchaudio.info(filename).num_frames
|
230 |
+
except:
|
231 |
+
return None
|
232 |
+
# make sure it wasn't empty, if so die
|
233 |
+
if num_frames == 0:
|
234 |
+
return None
|
235 |
+
sta = 0
|
236 |
+
if not self.whole_track:
|
237 |
+
if self.train:
|
238 |
+
sta = random.randint(0, num_frames - 441001)
|
239 |
+
else:
|
240 |
+
sta = (num_frames - 441001) // 2
|
241 |
+
num_frames = 441000
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
+
y, sr = torchaudio.load(filename, frame_offset=sta, num_frames=num_frames)
|
244 |
+
# resample
|
245 |
+
y = torchaudio.functional.resample(y, sr, 48000)
|
246 |
+
y = y[:, :441000]
|
247 |
+
# mono
|
248 |
+
y = y.mean(dim=0)
|
249 |
+
# normalize
|
250 |
+
y = int16_to_float32(float32_to_int16(y))
|
|
|
|
|
251 |
return y
|
252 |
|
253 |
def __getitem__(self, index):
|