views:

762

answers:

2

I need to analyze sound written in a .wav file. For that I need to transform this file into set of numbers (arrays, for example). I think I need to use wave-package. However, I do not know how exactly it works. For example I did the following:

import wave
w = wave.open('/usr/share/sounds/ekiga/voicemail.wav', 'r')
for i in range(w.getnframes()):
    frame = w.readframes(i)
    print frame

As a result of this code I expected to see sound-pressure as function of time. In contrast I see a lot of strange, mysterious symbols (which are not hexagonal numbers). Can anybody, pleas, help me with that?

A: 

If you're going to perform transfers on the waveform data then perhaps you should use SciPy, specifically scipy.io.wavfile.

Ignacio Vazquez-Abrams
OK. I just installed the SciPy but I cannot find any example of the usage of scipy.io.wavfile.
Roman
Nothing like the interactive interpreter for figuring out how things work! Be ambitious!
Ignacio Vazquez-Abrams
+3  A: 

Per the sources, scipy.io.wavfile.read(somefile) returns a tuple of two items: the first is the sampling rate in samples per second, the second is a numpy array with all the data read from the file. Looks pretty easy to use!

Alex Martelli