Returns the content of the i-th line in the index file.
(self, i: int)
| 68 | return len(self.filenames) |
| 69 | |
| 70 | def __getitem__(self, i: int) -> T.Any: |
| 71 | """Returns the content of the i-th line in the index file.""" |
| 72 | |
| 73 | filename = self.filenames[i] |
| 74 | if not os.path.exists(filename): |
| 75 | return None |
| 76 | |
| 77 | ext = os.path.splitext(filename)[1] |
| 78 | if ext.lower() == ".npy": |
| 79 | out = np.load(filename) |
| 80 | elif ext.lower() == ".npz": |
| 81 | # tmp = np.load(filename, allow_pickle=True) # returns a np file reader |
| 82 | # out = dict(**tmp) |
| 83 | # tmp.close() |
| 84 | tmp = np.load(filename, allow_pickle=True) # returns a np file reader |
| 85 | out = dict() |
| 86 | for key in tmp: |
| 87 | out[key] = tmp[key] |
| 88 | tmp.close() |
| 89 | elif ext.lower() == ".textgrid": |
| 90 | out = tgt.io.read_textgrid(filename) # tgt.core.TextGrid |
| 91 | elif ext.lower() in {".pt", ".pth"}: |
| 92 | # pytorch dict |
| 93 | out = torch.load(filename, map_location=torch.device("cpu")) |
| 94 | elif ext.lower() in {".json"}: |
| 95 | with open(filename, "r") as f: |
| 96 | out = json.load(f) |
| 97 | else: |
| 98 | raise NotImplementedError |
| 99 | |
| 100 | return out |
| 101 | |
| 102 | def get_uid(self, i: int): |
| 103 | """Return the uid of the i-th line in the index file. |