convert sac to wav

Hi,

Not sure if this helps, but with scipy.io.wavfile, you have to normalize and scale the amplitudes like in the example below.

Robin

import scipy.io.wavfile as wav

xspd = 200. # speed up by factor of 200
fswav = fs*xspd
wscal = p[0:M]/max(np.absolute(p[0:M])) # scale to -1 <= p <= 1; p is vector length M
wscal = 0.99*wscal # avoid clipping
convert_16_bit = float(2**15) # convert to int16 format for wavwrite
wscal = np.int16( wscal * convert_16_bit ) # convert to int16 format for wavwrite
wav.write('audio.wav',fswav,wscal)

Hello,

the WAV format is written by default as int32. And by default obspy
does not rescale the data. Most probable, your WAV file viewing tool
limits the yaxis to maximum [-1, +1], which corresponds to integer
[-2**31-1, 2**31-1]. If you zoom in a lot (approx factor 2E+9), you
will see the data.

To rescale the data to [-1, +1] use the rescale flag of st.write::

  from obspy.core import read
  st = read(‘http://examples.obspy.org/RJOB_061005_072159.ehz.new’)
  st.write(‘myfile.wave’, format=‘WAV’, framerate=7000, rescale=True)

See also:
http://docs.obspy.org/packages/autogen/obspy.wav.core.writeWAV.html#obspy.wav.core.writeWAV

Cheers,
mbyt

Robin's code or rescale=True or audacity produce similar results.

rescale=False is the default in writeWAV, but rescale=True seems more
useful "out of the box"...

thanks for all the tips.
rodrigo