<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import wave, struct
import matplotlib.pyplot as plt

def getSamples (name):
    obj = wave.open(name,'r')
    print( "Number of channels",obj.getnchannels())
    print ( "Sample width",obj.getsampwidth())
    print ( "Frame rate.",obj.getframerate())
    print ("Number of frames",obj.getnframes())
    print ( "parameters:",obj.getparams())

    nsamps = obj.getnframes()
    s = obj.readframes(nsamps)
    chans = obj.getnchannels()
    sampwidth = obj.getsampwidth()
    fr=obj.getframerate()

    unpstr = '&lt;{0}{1}'.format(nsamps*chans, {1:'b',2:'h',3:'i',4:'i',8:'q'}[sampwidth])
    x = list(struct.unpack(unpstr, s))

    #print x[0:20]


    #plt.plot(x[0:100])
    #plt.ylabel('part of the sample')
    #plt.show()

    print(nsamps,fr)
    
    return [nsamps,fr,x]
</pre></body></html>