Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get wave file properties using Python3 on Win32 environment?
    primarykey
    data
    text
    <p>1st I tried this:</p> <pre><code>import wave #read wave file I'm trying to open def getWaveInfo(): try: #get the list of wave file attributes im interested in (channels, famerate, frames number...) w = wave.open('wave.wav','rb') print("Number of channels is: ", w.getnchannels()) print("Sample width in bytes is: ", w.getsampwidth()) print("Framerate is: ", w.getframerate()) print("Number of frames is: ", w.getnframes()) except: print(wave.error) </code></pre> <p>Still got nothing. Then I changed into this:</p> <pre><code>import wave #read wave file I'm trying to open def getWaveInfo(): #get the list of wave file attributes im interested in (channels, famerate, frames number...) w = wave.open('wave.wav','rb') print("Number of channels is: ", w.getnchannels()) print("Sample width in bytes is: ", w.getsampwidth()) print("Framerate is: ", w.getframerate()) print("Number of frames is: ", w.getnframes()) if __main__ == '__main__': getWaveInfo() </code></pre> <p>Still nothing happens! I even used the C:\python wave.py > test.txt and the file is blank!</p> <p>All the code above is commented already. Any insights anyone on why this is not working? I'm using Windows 7 and Wing IDE 101 V5. Python 3.3.2</p> <p>I don't know what else to do to make it work... already debugged in Wings IDE and after the wave import nothing else works.</p> <p>Now my source code is like this:</p> <pre><code>import wave def getWaveInfo(): try: w = wave.open('audio.wav','rb') print("Number of channels is: ", w.getnchannels()) print("Sample width in bytes is: ", w.getsampwidth()) print("Framerate is: ", w.getframerate()) print("Number of frames is: ", w.getnframes()) except: print(w.error) </code></pre> <p>And I finally have raised an error(!): </p> <pre><code>Traceback (most recent call last): File "c:\audio.py", line 1, in &lt;module&gt; builtins.ImportError: bad magic number in 'wave': b'\x03\xf3\r\n' </code></pre> <p>My python filename was <code>"wave.py"</code> but now I changed it to <code>"audio.py"</code>. Also changed the audio wave file from <code>"wave.wav"</code> to <code>"audio.wav"</code></p> <p>Changed my code a little bit more and now its like this:</p> <pre><code>from wave import * def getWaveInfo(): w = wave.open('audio.wav','rb') print("Number of channels is: ", w.getnchannels()) print("Sample width in bytes is: ", w.getsampwidth()) print("Framerate is: ", w.getframerate()) print("Number of frames is: ", w.getnframes()) if __name__ == "__main__": getWaveInfo() </code></pre> <p>Now I have the error:</p> <pre><code>`Traceback (most recent call last): File "C:\Program Files (x86)\Wing IDE 101 5.0\src\debug\tserver\_sandbox.py", line 11, in &lt;module&gt; File "C:\Program Files (x86)\Wing IDE 101 5.0\src\debug\tserver\_sandbox.py", line 4, in getWaveInfo #print 'Exiting sandbox process' builtins.NameError: global name 'wave' is not defined` </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload