@@ -39,7 +39,7 @@ def __init__(
3939 self .overlap_ratio = overlap_ratio
4040
4141 self .n_frames = num_frames
42- self .n_seconds = self . n_frames / self . orig_freq
42+ self .n_seconds = 30
4343
4444 assert (
4545 self .overlap_ratio >= 0 and self .overlap_ratio < 1
@@ -57,18 +57,19 @@ def compute_segments_per_file(self):
5757
5858 i = 0
5959 for filepath in tqdm (self .filelist ):
60- try :
61- hop_size = self .n_seconds * self .overlap_ratio
60+ # try:
61+ hop_size = self .n_seconds * ( 1 - self .overlap_ratio )
6262
63- metadata = torchaudio .info (self .data_dir / filepath )
64- seconds = metadata .num_frames / metadata .sample_rate
65- n_segments = int (seconds / hop_size )
63+ metadata = torchaudio .info (self .data_dir / filepath )
64+ seconds = metadata .num_frames / metadata .sample_rate
6665
67- for j in range (n_segments ):
68- self .index [i ] = (filepath , j )
69- i += 1
70- except Exception as e :
71- print (f"Error processing file { filepath } " )
66+ n_segments = int (seconds / hop_size )
67+
68+ for j in range (n_segments ):
69+ self .index [i ] = (filepath , j )
70+ i += 1
71+ # except Exception as e:
72+ # print(f"Error processing file {filepath}")
7273
7374 def __len__ (self ):
7475 return len (self .index )
@@ -111,6 +112,9 @@ def __getitem__(self, idx):
111112 audio = audio .float ()
112113
113114 # TODO zero pad
115+ tgt_len = 720000
116+ if audio .size (0 ) < tgt_len :
117+ audio = torch .nn .functional .pad (audio , (0 , tgt_len - audio .size (0 )))
114118
115119 return audio , str (file_path )
116120
0 commit comments