def _extract_segment(self, filename): spec = np.load(self.work_dir + filename + '.orig.spec.npy') offset = self.RandomState.randint( 0, np.shape(spec)[1] - self.segment_length + 1) spec = spec[:, offset:offset + self.segment_length] delta = generate_delta(spec) return np.stack([spec, delta])
def _extract_all_segments(self, filename): spec = np.load(self.work_dir + filename + '.orig.spec.npy') segments = [] hop_length = self.segment_length // 5 offset = 0 while offset < np.shape(spec)[1] - self.segment_length: segment = spec[:, offset:offset + self.segment_length] delta = generate_delta(segment) offset += hop_length segments.append(np.stack([segment, delta])) return segments
def _extract_segment(self, filename): if self.DOWNSAMPLE: spec = np.load(self.work_dir + filename + '.mel.spec.ds.npy').astype('float32') else: spec = np.load(self.work_dir + filename + '.mel.spec.npy').astype('float32') offset = self.RandomState.randint( 0, np.shape(spec)[1] - self.SEGMENT_LENGTH + 1) spec = spec[:, offset:offset + self.SEGMENT_LENGTH] if self.WITH_DELTA: delta = generate_delta(spec) return np.stack([spec, delta]) else: return np.stack([spec])
def _extract_segment(self, filename): if self.DOWNSAMPLE: spec = np.load(self.work_dir + filename[:-4] + '.ds.npy').astype('float32') else: spec = np.load(self.work_dir + filename).astype('float32') spec = spec[:, :-1] # trim border artifacts if np.shape(spec)[1] >= self.SEGMENT_LENGTH: offset = self.RandomState.randint(0, np.shape(spec)[1] - self.SEGMENT_LENGTH + 1) spec = spec[:, offset:offset + self.SEGMENT_LENGTH] else: offset = self.RandomState.randint(0, self.SEGMENT_LENGTH - np.shape(spec)[1] + 1) overlay = np.zeros((self.BANDS, self.SEGMENT_LENGTH)) - 1.0 overlay[:, offset:offset + np.shape(spec)[1]] = spec spec = overlay if self.WITH_DELTA: delta = generate_delta(spec) return np.stack([spec, delta]) else: return np.stack([spec])
def _extract_all_segments(self, filename): if self.DOWNSAMPLE: spec = np.load(self.work_dir + filename + '.mel.spec.ds.npy').astype('float32') else: spec = np.load(self.work_dir + filename + '.mel.spec.npy').astype('float32') segments = [] hop_length = self.SEGMENT_LENGTH // 2 offset = 0 while offset < np.shape(spec)[1] - self.SEGMENT_LENGTH: segment = spec[:, offset:offset + self.SEGMENT_LENGTH] if self.WITH_DELTA: delta = generate_delta(segment) offset += hop_length if self.WITH_DELTA: segments.append(np.stack([segment, delta])) else: segments.append(np.stack([segment])) return segments