Reputation: 120
I am using tensorflow version 2.0
now I have a wav file which I load here
audio_file = tf.io.read_file(wav_path)
wav_array, sample_rate = tf.audio.decode_wav(
audio_file,
desired_channels=1)
wav_array = np.array(wav_array)
wav_array = wav_array.reshape(wav_array.shape[0])
then I get the short time Fourier transf using
spec = tf.signal.stft(wav_array, window_fn=tf.signal.hann_window,
frame_length=WIN_LEN, frame_step=HOP_LEN,fft_length=FFT_SIZE)
when I print the dims it is
Spectrogram shape: (748, 257)
Then I try to get the inverse using
inv = tf.signal.inverse_stft(spec,frame_length=WIN_LEN,
frame_step=HOP_LEN,fft_length=FFT_SIZE,
window_fn=tf.signal.hann_window)
but i get this error
AttributeError: 'int' object has no attribute 'value'
/usr/local/lib/python3.6/dist-
packages/tensorflow/python/ops/signal/spectral_ops.py in
inverse_stft(stfts, frame_length, frame_step, fft_length, window_fn,
name)
if (frame_length_static is None or
real_frames.shape.ndims is None or
--> real_frames.shape[-1].value is None):
real_frames = real_frames[..., :frame_length]
real_frames_rank = array_ops.rank(real_frames)
Upvotes: 2
Views: 943
Reputation: 4543
Diving deeper into the problem, I found out a workaround. TensorFlow requires fft_length
parameter to be integer for both inverse_stft
and stft
functions. If it's no provided, it will use compute it as described in docs.
For some reason, file spectral_ops.py
contains code, that first defines
real_frames = fft_ops.irfft(stfts, [fft_length]) #line 235
and then tries to access .value
of an integer multiple times
real_frames.shape[-1].value #lines 244, 255, 257
which throws
AttributeError: 'int' object has no attribute 'value'
to no surprise.
Removing call to .value
makes tf.signal.inverse_stft
produce expected result. It's arguably seems like a github issue.
Upvotes: 1