MCPcopy Create free account
hub / github.com/espnet/espnet / _random_crop_range

Method _random_crop_range

espnet2/train/preprocessor.py:1243–1276  ·  view source on GitHub ↗
(
        self, data_dict, num_spk, tgt_length, uid=None, max_trials=10
    )

Source from the content-addressed store, hash-verified

1241 data_dict[dereverb_ref_name] = func(data_dict[dereverb_ref_name])
1242
1243 def _random_crop_range(
1244 self, data_dict, num_spk, tgt_length, uid=None, max_trials=10
1245 ):
1246 # Randomly crop the signals to the length `tgt_length`
1247 assert tgt_length > 0, tgt_length
1248 speech_refs = [
1249 data_dict[self.speech_ref_name_prefix + str(spk + 1)]
1250 for spk in range(num_spk)
1251 ]
1252 length = speech_refs[0].shape[0]
1253 if length <= tgt_length:
1254 if length < tgt_length:
1255 logging.warning(
1256 f"The sample ({uid}) is not cropped due to its short length "
1257 f"({length} < {tgt_length})."
1258 )
1259 return 0, length
1260
1261 start = np.random.randint(0, length - tgt_length)
1262 count = 1
1263 if self.avoid_allzero_segment:
1264 # try to find a segment region that ensures all references are non-allzero
1265 while any_allzero([sf[start : start + tgt_length] for sf in speech_refs]):
1266 count += 1
1267 if count > max_trials:
1268 logging.warning(
1269 f"Can't find non-allzero segments for all references in {uid}."
1270 )
1271 break
1272 if start > 0:
1273 start = np.random.randint(0, start)
1274 else:
1275 break
1276 return start, start + tgt_length
1277
1278 @typechecked
1279 def _speech_process(

Callers 1

_speech_processMethod · 0.95

Calls 1

any_allzeroFunction · 0.85

Tested by

no test coverage detected