Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a seewave spectrogram into a wav file

I would like to manipulate a seewave audio spectrogram and then convert it back to a .wav file. A quick example

library(tuneR)
library(seewave)

data(tico)
#generate spectrogram with phase information
spec_tico=spectro(tico,plot=FALSE,complex=TRUE,norm=FALSE,dB=NULL)
#manipulate spectrogram
spec_tico_new=dostuff(spec_tico)
#convert back into Wave object - but there is no function spectr2Wave!
tico_new=spectr2Wave(spec_tico_new,...)

I haven't been able to find anything close to spectr2Wave in the seewave documentation.

Do you guys know a way how to convert it back without digging into the wav file specs and doing it manually? Thank you!

like image 654
cryo111 Avatar asked Oct 24 '25 00:10

cryo111


1 Answers

Turned out to be relatively simple! The important keyword that I was missing is "short-time Fourier transformation" - that is what seewave::spectro basically does. After googling for "inverse short-time Fourier transformation" the seewave function istft showed up.

library(tuneR)
library(seewave)

data(tico)
#generate spectrogram with phase information
spec_tico=spectro(tico,plot=FALSE,complex=TRUE,norm=FALSE,dB=NULL,ovlp=50)
#convert back into Wave object
tico_new=istft(spec_tico$amp,[email protected],ovlp=50,wl=512,output = "Wave")

Now enjoy the sound of Zonotrichia capensis(*)

#play on Windows
play(tico_new)
#play on Linux with vlc (or any other player ...)
play(tico_new,player="cvlc")
#on Linux you have to kill the two vlc processES afterwards!

(*) that's the bird that you can hear if you execute the play command. :)

like image 67
cryo111 Avatar answered Oct 26 '25 15:10

cryo111



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!