def __call__(self, x, rate=None, **kwargs): if rate is not None and rate != self.sample_frequency: raise RuntimeError( f"Sampling rate {rate}Hz of input WAV must be the same as the " f"sampling rate {self.sample_frequency}Hz expected by feature " f"computer.") try: if len(kwargs) > 0: full_kwargs = self.default_kwargs.copy() full_kwargs.update(kwargs) else: full_kwargs = self.default_kwargs if hasattr(self.computer, "compute"): output = self.computer.compute(matrix.Vector(x), **full_kwargs) else: output = self.computer(matrix.Vector(x), **full_kwargs) if not isinstance(output, np.ndarray): output = output.numpy() except AttributeError as e: if "computer" in str(e): raise NotImplementedError( "All subclasses of KaldiFeatures must initialize self.computer " "as either a kaldi.feat.* feature computer, or a method returning " "a Kaldi feature matrix.") else: raise e except TypeError as e: if "Required argument" in str(e): raise NotImplementedError( "Either override self.default_kwargs to provide default values " "for all additional args required by self.computer.compute, or " "provide them explicitly to __call__.") else: raise e if output.shape[0] == 0: raise RuntimeError( f"For input wav with shape {x.shape} at sampling " f"frequency {self.sample_frequency}, output had length 0.") return output
def write(self, key, value): """Writes the `(key, value)` pair to the table. This method is provided for compatibility with the C++ API only; most users should use the Pythonic API. Overrides write to accept both Vector and SubVector. Args: key (str): The key. value: The value. """ super(VectorWriter, self).write(key, _matrix.Vector(value))
def computer(self, x): return feat.pitch.compute_and_process_kaldi_pitch( self.pitch_opts, self.process_opts, matrix.Vector(x))