Spaces:
Runtime error
Runtime error
Download encoder/data_objects/utterance.py from jewelt123/CloneABC01: direct link, hf CLI and curl.
- Browser
- Download file 880 Bytes
-
https://huggingface.co/spaces/jewelt123/CloneABC01/resolve/ea0a6c1f3d870d1ec91311d6c7f45a78bd6b3dcb/encoder/data_objects/utterance.py
- Command line
-
hf download hf://spaces/jewelt123/CloneABC01@ea0a6c1f3d870d1ec91311d6c7f45a78bd6b3dcb/encoder/data_objects/utterance.py
-
curl -L -o utterance.py https://huggingface.co/spaces/jewelt123/CloneABC01/resolve/ea0a6c1f3d870d1ec91311d6c7f45a78bd6b3dcb/encoder/data_objects/utterance.py
880 Bytes
| import numpy as np | |
| class Utterance: | |
| def __init__(self, frames_fpath, wave_fpath): | |
| self.frames_fpath = frames_fpath | |
| self.wave_fpath = wave_fpath | |
| def get_frames(self): | |
| return np.load(self.frames_fpath) | |
| def random_partial(self, n_frames): | |
| """ | |
| Crops the frames into a partial utterance of n_frames | |
| :param n_frames: The number of frames of the partial utterance | |
| :return: the partial utterance frames and a tuple indicating the start and end of the | |
| partial utterance in the complete utterance. | |
| """ | |
| frames = self.get_frames() | |
| if frames.shape[0] == n_frames: | |
| start = 0 | |
| else: | |
| start = np.random.randint(0, frames.shape[0] - n_frames) | |
| end = start + n_frames | |
| return frames[start:end], (start, end) |