M
M
Maruto2021-07-29 15:43:20
Python
Maruto, 2021-07-29 15:43:20

How to get an audio file from a power spectogram image?

Good afternoon. I am converting audio to picture with the following code without converting stft to absolute numbers so as not to lose data. As I understand it, I don’t lose anything at all, in order to restore the original sound, correct me if it’s wrong.

path = '/content/drive/MyDrive/originalputin/2.mp3.wav'

audio, sr = librosa.load(path)

print('length of the audio:',len(audio)/sr)

audio_stft = librosa.stft(audio)

audio_stft_db = librosa.power_to_db(audio_stft)

print('audio_stft.shape:',audio_stft.shape)
print('audio_stft_db.shape:',audio_stft_db.shape)

import matplotlib.pyplot as plt
import librosa.display

fig, ax = plt.subplots()
img = librosa.display.specshow(audio_stft_db, y_axis='log', x_axis='time', ax=ax)
ax.set_title('Power spectrogram')
fig.colorbar(img, ax=ax, format="%+2.0f dB")


At the output I get a picture. Something like this.

6102a1f231ac8891105034.png

Questions.

1) How can I download only the picture of this spectogram without losing quality? To without frames, without a scale. Most importantly, no loss of quality at all.

2) How can I get the original audio file again from this picture without losing quality?

Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question