espnet2.enh.separator.svoice_separator.overlap_and_add
Less than 1 minute
espnet2.enh.separator.svoice_separator.overlap_and_add
espnet2.enh.separator.svoice_separator.overlap_and_add(signal, frame_step)
Reconstructs a signal from a framed representation.
This function adds potentially overlapping frames of a signal with shape […, frames, frame_length], offsetting subsequent frames by frame_step. The resulting tensor has shape […, output_size] where
output_size = (frames - 1) * frame_step + frame_length.
- Parameters:
- signal – A Tensor of shape […, frames, frame_length]. All dimensions may be unknown, and the rank must be at least 2.
- frame_step – An integer denoting overlap offsets. Must be less than or equal to frame_length.
- Returns: A Tensor with shape […, output_size] containing the overlap-added frames of signal’s inner-most two dimensions. The output_size is calculated as: output_size = (frames - 1) * frame_step + frame_length.
Examples
>>> import torch
>>> signal = torch.randn(2, 4, 8) # 2 batches, 4 frames, 8 length
>>> frame_step = 4
>>> output = overlap_and_add(signal, frame_step)
>>> output.shape
torch.Size([2, 8]) # output size should be (4 - 1) * 4 + 8 = 8
NOTE
This function is based on the implementation found in TensorFlow: https://github.com/tensorflow/tensorflow/blob/r1.12/tensorflow/contrib/signal/python/ops/reconstruction_ops.py