# Recover Audio from Spectrogram Image

I have applied transformation(Constant Q Transformation) to my audio time domain signal, this gives me Frequency vs Time representation. Now, the CQT values consists of complex values(84*260), but python makes use of only magnitude values to plot. I saved obtained spectrogram as .png image, to do some image processing work. So when i read this saved image I get 224*341*3.

After Image processing work, Now I want to reconstruct back my audio time domain signal to check my work. To reconstruct back to audio domain time signal, first i will read the image, when i read my image I get 224*341*3 values.

I have the phase information of 84*260 resulted from CQT in the beginning. I know we have to make use of phase information to reconstruct the signal. S=Magnitude * Phase.

How would one really reconstruct back the audio signal with this criteria.

Am i doing anything wrong. Has people came across same situations?

I am using Python and librosa library for all the operations.

Edit:

I know librosa icqt has existing bug. Even if I do reconstruction in matlab, how would i tackle the different dimensions. Hope its clear now.

Code:

#load the audio

#find the cqt
cqt = librosa.core.cqt(data_aud, sr=44100, hop_length=512, n_bins=84, bins_per_octave=12, tuning=None, norm=1, sparsity=0.01, window='hann', scale=True, pad_mode='reflect')

#take the phase information
mag, phase = librosa.core.magphase(cqt,power = 1)

#save the fig
plt.axis('off')
plt.savefig(path,transparent = True, bbox_inches = 'tight', pad_inches = 0)

#image processing
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

#multiply the image data with phase????
#reconstruct
y =librosa.core.icqt(imageData, sr=44100, hop_length=512, fmin=None, bins_per_octave=12, tuning=None, filter_scale=1, norm=1, sparsity=0.01, window='hann', scale=True, amin=1e-06)

• Hi Krish, and welcome to DSP.SE! I think it is not clear what your exact conditions are, and they are important to know for people to be able to help you. For example, you write that "[t]he CQT has 84*260 values", but what is "the CQT" in this case - to what signal did you apply it to obtain 84*260 values? – applesoup Feb 12 '19 at 20:39
• @applesoup I edited in more deeper way, hope its clear now. – Krish Feb 13 '19 at 11:52
• Can you post the code? – applesoup Feb 13 '19 at 13:34
• @applesoup Done! – Krish Feb 14 '19 at 10:58