[NTLUG:Discuss] WAV file analysis
Ralph Green
sfreader at sbcglobal.net
Tue Feb 3 06:37:07 CST 2009
On Mon, 2009-02-02 at 07:55 -0600, Leroy Tennison wrote:
> Admittedly OT but hopefully someone can help. Does anyone know of a
> program which will analyze a WAV file for proper format? It could be a
Howdy,
I am enclosing a simple python program to do what you ask for. Look
at it and modify it as to make it more useful. Right now, you pass it
the file name of a wave file. It looks at the header to see what the
size should be and compares that to the actual size. If they are
different, it prints a message. If the file size looks right, it prints
nothing.
import struct
import os
import sys
if len(sys.argv) < 2:
print 'Incorrect Command Line Syntax ...'
print ' '
print 'Usage: Python testWavSize.py </Filepath/Filename.Ext> <Enter>'
print ' '
print sys.exit()
#infile = open(sys.argv[1], 'r')
f = open(sys.argv[1],"rb")
# read the file header
# This is the Format of the Wave Header (44 Bytes)
# See the helpfiles for struct, wave format
fmtstr = "4sL4s4sLhhLLhh4sL"
header = struct.unpack(fmtstr,f.read(44))
#print header # print it out as a tuple
(ID, Chunksize,Format,SubChunkID,
SubChunkSize,AudioFmt,Channels,SampleRate,
ByteRate,BlockAlign,BitsPerSample,
Subchunk2ID,Subchunk2Size) = header
f.close()
actualSize = os.path.getsize(sys.argv[1])
if Chunksize+8 != actualSize:
print "The Header thinks the file size is %d, while the filesize is
really %d" \
% (Chunksize+8, actualSize)
More information about the Discuss
mailing list