4

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!

cryo111
  • 4,444
  • 1
  • 15
  • 37
  • @Vlo I use `complex=TRUE` - so I will get complex numbers from the FFT. I should be able to obtain the phase from the complex numbers. – cryo111 Aug 26 '15 at 15:31
  • @Vlo I am not sure whether you get notified by this comment since you have deleted your comment - but just in case you are interested: I have found a solution. And thank you for your interesting link. – cryo111 Aug 26 '15 at 19:32

1 Answers1

7

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,f=tico@samp.rate,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. :)

cryo111
  • 4,444
  • 1
  • 15
  • 37