Skip to content Skip to sidebar Skip to footer

Python: Reconstruct Audio File From STFT

As a simple experiment, I want to compute the stft of an audio file: sample_rate, samples = wav.read(file) f, t, Zxx = stft(samples, sample_rate) _, reconstructed = istft(Zxx, sam

Solution 1:

As suggested by Warren:

print (samples.shape)
print (samples.dtype)
print (reconstructed.dtype)

Output:

(9218368,)
int16
float64

According to the scipy docs int and float input have different meaning when writing a wav file. I tried casting reconstructed to np.int16:

rounded_reconstructed = np.rint(reconstructed).astype(np.int16)

test_file = os.path.join(temp_folder, 'reconstructed.wav')
wav.write(test_file, sample_rate, rounded_reconstructed)

The result is barely distinguishable from the original. Thank you for the help.


Post a Comment for "Python: Reconstruct Audio File From STFT"