elif filter == "ZCR": self.data.append(sample.zcr) elif filter == "STE": self.data.append(sample.ste) else: print "Unknown filter type : %s" % filter def calc(self): # Calculate the new threshold value if len(self.data) > 0: self.threshold = numpy.average(numpy.array(self.data)) return self.threshold changed = False # It will set to True if the result should be saved. table = SoundTable() # For collect the phonetic data from sampling file stat = {} print "Reading sound.csv..." try: table.open("sound.csv") except IOError,e: print "Warn: Fail to open %s. " % ("sound.csv") changed = True print "%d of record(s) read." % len(table) for sound in table: item = Stat()
def highPass(self): # A high pass filter on RMS. A dirty hack for right-endpoint searching while self._sampling[self._index]["RMS"] > 0.03: self._index = self._index+1 frame = self._sampling[self._index] self._index = self._index + 1 return frame try: target = sys.argv[1] except: print "Usage: %s name_of_sample " % sys.argv[0] exit(0) table = SoundTable() print "Reading sound.csv..." table.open("sound.csv") samplingFile = SamplingFile() filename = target + "-sampling.csv" print "Reading %s..." % filename samplingFile.open(filename) filename = target + ".txt" print "Reading %s..." % filename f = codecs.open(filename,"r","utf-8") line = f.readline() phonetics = [ Ipa(item.strip()) for item in line.split(" ") ]