def tflite_compat_mel_from_samples(samples, hparams): """EXPERIMENTAL: Log mel spec with ops that can be made TFLite compatible.""" features = melspec_input.build_mel_calculation_graph( samples, hparams.sample_rate, window_length_seconds=2048 / hparams.sample_rate, hop_length_seconds=(hparams.spec_hop_length / hparams.sample_rate), num_mel_bins=hparams.spec_n_bins, lower_edge_hz=hparams.spec_fmin, upper_edge_hz=hparams.sample_rate / 2.0, frame_width=1, frame_hop=1, tflite_compatible=False) # False here, but would be True on device. return tf.squeeze(features, 1)
def BuildTfGraph(self, tflite_compatible=False): """Setup the TF graph using the single function under test.""" if tflite_compatible: # tflite requires explicit input sizing. input_length = len(self._test_waveform) else: input_length = None with self._graph.as_default(): waveform_input = tf.placeholder(tf.float32, [input_length]) # This is the single function provided by the library. features = melspec_input.build_mel_calculation_graph( waveform_input, tflite_compatible=tflite_compatible) self._input = waveform_input self._output = features
def tflite_compat_mel(wav_audio, hparams): """EXPERIMENTAL: Log mel spec with ops that can be made TFLite compatible.""" samples, decoded_sample_rate = tf.audio.decode_wav( wav_audio, desired_channels=1) samples = tf.squeeze(samples, axis=1) with tf.control_dependencies( [tf.assert_equal(decoded_sample_rate, MELSPEC_SAMPLE_RATE)]): features = melspec_input.build_mel_calculation_graph( samples, MELSPEC_SAMPLE_RATE, window_length_seconds=2048 / MELSPEC_SAMPLE_RATE, # 0.128 hop_length_seconds=( hparams.spec_hop_length / MELSPEC_SAMPLE_RATE), # 0.032 num_mel_bins=hparams.spec_n_bins, lower_edge_hz=hparams.spec_fmin, upper_edge_hz=MELSPEC_SAMPLE_RATE / 2.0, frame_width=1, frame_hop=1, tflite_compatible=False) # False here, but would be True on device. return tf.squeeze(features, 1)
def tflite_compat_mel_from_samples(samples, hparams): """EXPERIMENTAL: Log mel spec with ops that can be made TFLite compatible.""" # Ensure hparams.sample_rate is MELSPEC_SAMPLE_RATE because that is what these # parameters are hard coded to expect. with tf.control_dependencies( [tf.assert_equal(hparams.sample_rate, MELSPEC_SAMPLE_RATE)]): features = melspec_input.build_mel_calculation_graph( samples, MELSPEC_SAMPLE_RATE, window_length_seconds=2048 / MELSPEC_SAMPLE_RATE, # 0.128 hop_length_seconds=(hparams.spec_hop_length / MELSPEC_SAMPLE_RATE), # 0.032 num_mel_bins=hparams.spec_n_bins, lower_edge_hz=hparams.spec_fmin, upper_edge_hz=MELSPEC_SAMPLE_RATE / 2.0, frame_width=1, frame_hop=1, tflite_compatible=False ) # False here, but would be True on device. return tf.squeeze(features, 1)