0

I followed this example to compute mfcc using tensorflow. To visualize I tried to use matplotlib as mentioned here. But it says

Tensor objects are not iterable when eager execution is not enabled. To iterate over this tensor use tf.map_fn.

When I do print(mfccs) insead of plt.plot(mfccs) and plt.show() I get

Tensor("strided_slice_2:0", shape=(0, 13), dtype=float32)

Below is the example code. Similar to here

import functools
import tensorflow as tf
from tensorflow.contrib.signal.python.ops import window_ops
from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio
from tensorflow.contrib import ffmpeg

sampling_rate = 44000
audio_file = tf.placeholder(tf.string)
audio_binary = tf.read_file(audio_file)

desired_channels = 1
waveform = tf.contrib.ffmpeg.decode_audio(
 audio_binary,
file_format="wav",
 desired_channels=desired_channels,
 desired_samples=sampling_rate,
 name='decoded_sample_data')

transwav = tf.transpose(waveform[0])

with tf.name_scope('Energy_Spectogram'):
    fft_frame_length = 512
    fft_frame_step =  512 
    window_fn = functools.partial(window_ops.hann_window, periodic=True)
    stft = tf.contrib.signal.stft(signals=transwav, frame_length=fft_frame_length, frame_step=fft_frame_step,
                                  window_fn=window_fn)
    istft = tf.contrib.signal.inverse_stft(stfts=stft, frame_length=fft_frame_length, frame_step=fft_frame_step,
    window_fn=tf.contrib.signal.inverse_stft_window_fn(fft_frame_step,
                                           forward_window_fn=window_fn))

with tf.Session() as sess:
    original, reconstructed = sess.run([transwav, istft])

import matplotlib.pyplot as plt

plt.plot(original)
plt.plot(reconstructed)
plt.show()

Any suggestions. Thanks

HelloWorld
  • 11
  • 2
  • 1
    Please, provide us with a [**minimal**, **complete**, and **verifiable** example](https://stackoverflow.com/help/mcve). – nbro Jul 06 '18 at 13:07
  • 1
    Also, note, your title starts with "how to plot tensorflow". However, of course, you can't plot a library. Please, be more careful and precise when you write a post. – nbro Jul 06 '18 at 13:09
  • @nbro have added an example. There is problem with ffmpeg in windows, so cant replicate it myself. But it should be working in linux.Thanks – HelloWorld Jul 07 '18 at 22:11

0 Answers0