Ejemplo n.º 1
0
def compute_spectrum():
    parser = get_parser()
    args = parser.parse_args()

    config = {}
    config['sample_rate'] = float(args.sample_rate)
    config['output_type'] = int(args.output_type)
    config['window_length'] = args.window_length
    config['frame_length'] = args.frame_length

    spectrum = Spectrum.params(config).instantiate()

    with kaldiio.ReadHelper(args.rspecifier,
                            segments=args.segments) as reader, \
          KaldiWriter(args.wspecifier, write_num_frames=args.write_num_frames,
                      compress=args.compress, compression_method=args.compression_method) as writer:
        for utt_id, (sample_rate, array) in reader:
            if sample_rate != args.sample_rate:
                args.sample_rate = sample_rate
            array = array.astype(np.float32)
            audio_data = tf.constant(array, dtype=tf.float32)
            spectrum_test = spectrum(audio_data, args.sample_rate)
            sess = tf.compat.v1.Session()
            spectrum_feats = spectrum_test.eval(session=sess)
            writer[utt_id] = spectrum_feats
Ejemplo n.º 2
0
    def test_spectrum(self):
        wav_path = str(
            Path(PACKAGE_ROOT_DIR).joinpath('layers/ops/data/sm1_cln.wav'))

        with self.cached_session(use_gpu=False, force_gpu=False):
            read_wav = ReadWav.params().instantiate()
            input_data, sample_rate = read_wav(wav_path)

            spectrum = Spectrum.params({'window_length': 0.025}).instantiate()
            spectrum_test = spectrum(input_data, sample_rate)

            output_true = np.array(
                [[-16.863441, -16.910473, -17.077059, -16.371634, -16.845686],
                 [-17.922068, -20.396345, -19.396944, -17.331493, -16.118851],
                 [-17.017776, -17.551350, -20.332376, -17.403994, -16.617926],
                 [-19.873854, -17.644503, -20.679525, -17.093716, -16.535091],
                 [-17.074402, -17.295971, -16.896650, -15.995432, -16.560730]])

            self.assertEqual(tf.rank(spectrum_test).eval(), 2)
            self.assertAllClose(spectrum_test.eval()[4:9, 4:9], output_true)
Ejemplo n.º 3
0
  def test_spectrum(self):
    wav_path = str(
        Path(PACKAGE_ROOT_DIR).joinpath('layers/ops/data/sm1_cln.wav'))

    with self.cached_session(use_gpu=False, force_gpu=False):
      read_wav = ReadWav.params().instantiate()
      input_data, sample_rate = read_wav(wav_path)

      spectrum = Spectrum.params({
          'window_length': 0.025,
          'snip_edges': 1
      }).instantiate()
      spectrum_test = spectrum(input_data, sample_rate)

      output_true = np.array(
          [[9.819611, 2.84503, 3.660894, 2.7779, 1.212233],
           [9.328745, 2.553949, 3.276319, 3.000918, 2.499342]])

      self.assertEqual(tf.rank(spectrum_test).eval(), 2)
      self.assertAllClose(
          spectrum_test.eval()[0:2, 0:5], output_true, rtol=1e-05, atol=1e-05)