class Dataset: # Dataset is a set of files associated with an audio file. # The name of a dataset is same as the audio file. # This class is an utility to manage this set of files def __init__(self,name): self.name = name # A list of word(formed by phonetic) self.charList = [] self._phoneticList = [] self._labelFile = None def open(self): charFile = open(self.name+".txt","r") line = charFile.readline() self.charList = [unicode(item,"utf-8") for item in line.split(" ")] self._labelFile = LabelFile() self._labelFile.open(self.name + "-label.txt") self._samplingFile = SamplingFile() self._samplingFile.open(self.name + "-sampling.csv") self._createPhoneticList() def phoneticList(self): return self._phoneticList def _createPhoneticList(self): for row in self._labelFile: sample = Sample() sample.timestamp = row[0] sample.phonetic = Ipa.simplifySymbol(row[2]) record = self._samplingFile.search(float(row[0])); sample.zcr = float(record["ZCR"]) sample.variance = float(record["Spectrum Variance"]) sample.rms = float(record["RMS"]) sample.str = float(record["STE"]) self._phoneticList.append(sample)
def open(self): charFile = open(self.name+".txt","r") line = charFile.readline() self.charList = [unicode(item,"utf-8") for item in line.split(" ")] self._labelFile = LabelFile() self._labelFile.open(self.name + "-label.txt") self._samplingFile = SamplingFile() self._samplingFile.open(self.name + "-sampling.csv") self._createPhoneticList()
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(" ") ] filter = Filter() filter.process(table,samplingFile,phonetics)