def specgrams_to_melspecgrams(self, specgrams): """Converts specgrams to melspecgrams. Args: specgrams: Tensor of log magnitudes and instantaneous frequencies, shape [batch, time, freq, 2]. Returns: melspecgrams: Tensor of log magnitudes and instantaneous frequencies, shape [batch, time, freq, 2], mel scaling of frequencies. """ if self._mel_downscale is None: return specgrams logmag = specgrams[:, :, :, 0] p = specgrams[:, :, :, 1] mag2 = tf.exp(2.0 * logmag) phase_angle = tf.cumsum(p * np.pi, axis=-2) l2mel = tf.to_float(self._linear_to_mel_matrix()) logmelmag2 = self._safe_log(tf.tensordot(mag2, l2mel, 1)) mel_phase_angle = tf.tensordot(phase_angle, l2mel, 1) mel_p = spectral_ops.instantaneous_frequency(mel_phase_angle) return tf.concat( [logmelmag2[:, :, :, tf.newaxis], mel_p[:, :, :, tf.newaxis]], axis=-1)
def melspecgrams_to_specgrams(self, melspecgrams): """Converts melspecgrams to specgrams. Args: melspecgrams: Tensor of log magnitudes and instantaneous frequencies, shape [batch, time, freq, 2], mel scaling of frequencies. Returns: specgrams: Tensor of log magnitudes and instantaneous frequencies, shape [batch, time, freq, 2]. """ if self._mel_downscale is None: return melspecgrams logmelmag2 = melspecgrams[:, :, :, 0] mel_p = melspecgrams[:, :, :, 1] mel2l = tf.to_float(self._mel_to_linear_matrix()) mag2 = tf.tensordot(tf.exp(logmelmag2), mel2l, 1) logmag = 0.5 * self._safe_log(mag2) mel_phase_angle = tf.cumsum(mel_p * np.pi, axis=-2) phase_angle = tf.tensordot(mel_phase_angle, mel2l, 1) p = spectral_ops.instantaneous_frequency(phase_angle) return tf.concat([logmag[:, :, :, tf.newaxis], p[:, :, :, tf.newaxis]], axis=-1)
def stfts_to_specgrams(self, stfts): """Converts stfts to specgrams. Args: stfts: Complex64 tensor of stft, shape [batch, time, freq, 1]. Returns: specgrams: Tensor of log magnitudes and instantaneous frequencies, shape [batch, time, freq, 2]. """ stfts = stfts[:, :, :, 0] logmag = self._safe_log(tf.abs(stfts)) phase_angle = tf.angle(stfts) if self._ifreq: p = spectral_ops.instantaneous_frequency(phase_angle) else: p = phase_angle / np.pi return tf.concat([logmag[:, :, :, tf.newaxis], p[:, :, :, tf.newaxis]], axis=-1)