espnet2.train.preprocessor.framing
Less than 1 minute
espnet2.train.preprocessor.framing
espnet2.train.preprocessor.framing(x, frame_length: int = 512, frame_shift: int = 256, centered: bool = True, padded: bool = True)
Segment an input array into overlapping frames.
This function divides the input array x into overlapping frames of specified length and shift. It can also pad the input and center the frames based on the provided parameters.
- Parameters:
- x (np.ndarray) – The input array to be framed.
- frame_length (int , optional) – The length of each frame. Must be a positive integer. Defaults to 512.
- frame_shift (int , optional) – The number of samples to shift for the next frame. Must be greater than 0. Defaults to 256.
- centered (bool , optional) – If True, pads the input array on both sides to center the frames. Defaults to True.
- padded (bool , optional) – If True, pads the input array to ensure an integer number of frames can be created. Defaults to True.
- Returns: A 2D array where each row represents a frame of frame_length samples.
- Return type: np.ndarray
- Raises:
- ValueError – If the input array size is zero, if
- frame_length –
- than the input length**, or** if frame_shift is less than or –
- equal to 0. –
Examples
>>> x = np.random.rand(1024) # Sample input
>>> frames = framing(x, frame_length=512, frame_shift=256)
>>> frames.shape
(3, 512) # Three frames of length 512
NOTE
The output array will have shape (num_frames, frame_length), where num_frames is calculated based on the input size, frame length, and frame shift.