# python script to calculate average bitrates # invoked as follows: # python bitrate.py [wavlist] [compressedlist] # wavlist is a text file which contains a list of WAV filenames # compressedlist is a text file which contains a list of the corresponding # compressed filenames. The ordering of the filenames must be the same # as in wavlist. import sys import os import wave import string duration = [] inf1 = file(sys.argv[1], 'r') for line in inf1.readlines(): sline = string.strip(line) inw = wave.open(sline, 'rb') duration.append(1.0 * inw.getnframes() / inw.getframerate()) inw.close() inf1.close() fsize = [] inf2 = file(sys.argv[2], 'r') for line in inf2.readlines(): sline = string.strip(line) st = os.stat(sline) fsize.append(st.st_size) inf2.close() bitrate = [] i = 0 sumduration = 0 sumsize = 0 for fs in fsize: sumduration = sumduration + duration[i] sumsize = sumsize + fsize[i] bitrate.append(fsize[i]/duration[i] * 8.0 / 1000) i = i + 1 print bitrate average_bitrate = sumsize/sumduration * 8.0 / 1000 print average_bitrate