def loadAudioFile(self): self.formantPlotCanvas.delete("loadedLines") os.chdir("../..") self.xLoadedPlotList = [] self.yLoadedPlotList = [] self.loadedPlots = True print os.getcwd() filename = tkFileDialog.askopenfilename(initialdir="Recording") radius = self.formantRadius self.formantPlotCanvas.delete('loadedPlots') self.loadedAudio.config(load=filename) os.chdir("Formant/dist") import wave import contextlib fname = filename with contextlib.closing(wave.open(fname, 'r')) as f: frames = f.getnframes() rate = f.getframerate() duration = float(frames) / float(rate) loadedPlots = SoundProcessing.getFormants(self.loadedAudio, self.gender, True) probabilityOfVoicingList = SoundProcessing.getProbabilityOfVoicing( self.loadedAudio, True) self.formantPlotCanvas.delete('loadedPlots') sleeptime = float(duration) / len(probabilityOfVoicingList) thread.start_new_thread( self.multiThreadLoader, ("Thread-2", sleeptime, probabilityOfVoicingList, loadedPlots))
def plotFormants(self, sound): probabilityOfVoicing = SoundProcessing.getProbabilityOfVoicing(sound,False) if probabilityOfVoicing == 1.0: formants = SoundProcessing.getFormants(sound,self.gender,False) #Only plot the latest formants of the sound if there's a good chance that it is the user speaking instead of background noise. if formants != None: #self.f1List.append(formants[0]) #self.f2List.append(formants[1]) latestF1 = formants[0]/SCALEDOWN latestF2 = FORMANTPLOTWIDTH - (formants[1]/SCALEDOWN) + XSHIFT + XOFFSET #if abs(self.previousF1-latestF1) < 150 and abs(self.previousF2-latestF2) < 150: #print latestF1 #print latestF2 #print "\n\n" if latestF2 > XSHIFT and latestF1 < FORMANTPLOTHEIGHT-YSHIFT: self.formantPlotCanvas.create_oval(latestF2-2,latestF1-2,latestF2+2,latestF1+2, fill='black', tags="userformants") #self.previousF1 = latestF1 #self.previousF2 = latestF2 if not self.isRecording: if formants != None: #print self.soundCopy.formant() #print self.f1List #print self.f2List print ""
def loadAudioFile(self): filename = tkFileDialog.askopenfilename(initialdir=self.appDirectory) self.formantPlotCanvas.delete('loadedformants') self.loadedAudio.config(load=filename) #self.playLoadButton.config(state='normal') loadedFormants = SoundProcessing.getFormants(self.loadedAudio, self.gender, True) probabilityOfVoicingList = SoundProcessing.getProbabilityOfVoicing( self.loadedAudio, True) self.formantPlotCanvas.delete('loadedformants') try: for i in range(0, len(loadedFormants)): probabilityOfVoicing = probabilityOfVoicingList[i] if probabilityOfVoicing == 1.0: formant = loadedFormants[i] f1 = formant[0] / SCALEDOWN f2 = FORMANTPLOTWIDTH - (formant[1] / SCALEDOWN) + XSHIFT + XOFFSET if f2 - 100 > XSHIFT and f1 + 100 < FORMANTPLOTHEIGHT - YSHIFT: self.formantPlotCanvas.create_oval( f2 - 100 - 2, f1 + 100 - 2, f2 - 100 + 2, f1 + 100 + 2, fill='yellow', tags="loadedformants") except IndexError: print ""
def plotFormants(self, sound): probabilityOfVoicing = SoundProcessing.getProbabilityOfVoicing(sound, False) if probabilityOfVoicing == 1.0: formants = SoundProcessing.getFormants(sound, self.gender, False) # Only plot the latest formants of the sound if there's a good chance that it is the user speaking instead of background noise. if formants != None: latestF1 = formants[0] / SCALEDOWN latestF2 = FORMANTPLOTWIDTH - (formants[1] / SCALEDOWN) + XSHIFT + XOFFSET if self.id == 0: latestF2 = latestF2 * 1.5 - 400 latestF1 = latestF1 * 2 - 100 elif self.id == 1: latestF2 = latestF2 * 1.5 - 400 latestF1 = latestF1 * 2.7 - 300 elif self.id == 2: latestF2 = latestF2 * 1.2 - 130 latestF1 = latestF1 * 1.8 - 130 elif self.id == 3: latestF2 = latestF2 * 1.5 - 330 latestF1 = latestF1 * 2.7 - 300 if latestF2 > XSHIFT and latestF1 < FORMANTPLOTHEIGHT - YSHIFT: self.formantPlotCanvas.create_oval( latestF2 - 2, latestF1 - 2, latestF2 + 2, latestF1 + 2, fill="black", tags="userformants" ) if not self.isRecording: if formants != None: print ""
def plotFormants(self, sound): #SCALEREFIXTHIS self.hasPlots = True self.vowelPlotCanvas.delete('arrow') #Gets the probablity of sound being a voice for the last formant in the sound file. (false means last formant, true means all formants) probabilityOfVoicing = SoundProcessing.getProbabilityOfVoicing( sound, False) if True: #probabilityOfVoicing == 1.0: formant = SoundProcessing.getFormants(sound, self.id, False) #Only plot the latest formants of the sound if there's a good chance that it is the user speaking instead of background noise. if formant != None: radius = 3 color = 'black' yFormant = formant[0] xFormant = formant[1] (x, y) = self.switchCoorSystems(xFormant, yFormant) #Remove some background noise. if ((self.prevX - x)**2 + (self.prevY - y)**2)**0.5 < 28: self.vowelPlotCanvas.create_oval(x - radius, y - radius, x + radius, y + radius, fill=color, tags="userformants") self.xFormantList.append(xFormant) self.yFormantList.append(yFormant) self.plotCount += 1 if self.plotCount > 250: self.stop() #self.root.after(100 , self.displayFinalScore) self.distanceToScore(xFormant, yFormant) if (abs(y - self.y) > self.height): pass self.prevX = x self.prevY = y
def plotFormants(self, sound): #Gets the probablity of sound being a voice for the last formant in the sound file. (false means last formant, true means all formants) probabilityOfVoicing = SoundProcessing.getProbabilityOfVoicing( sound, False) if probabilityOfVoicing == 1.0: formant = SoundProcessing.getFormants(sound, self.id, False) #Only plot the latest formants of the sound if there's a good chance that it is the user speaking instead of background noise. if formant != None: (xScale, xShift, yScale, yShift) = self.getPlotScaleInfo(self.vowelType) #GetUser default or user defined colour and radius for the individual formants radius = self.formantRadius color = self.formantColour yPreScale = formant[0] / SCALEDOWN xPreScale = PLOTWIDTH - (formant[1] / SCALEDOWN) + XSHIFT + XOFFSET x = (xPreScale * xScale - xShift) y = (yPreScale * yScale - yShift) self.count += 1 #Only plot of the Points are on the Grid. They can go over the axis though. if (x > 0) and (y < PLOTHEIGHT): distance = (((x - self.prevX)**2 + (y - self.prevY)**2)**(0.5)) if (distance < self.backgroundNoiseDistance) and distance > 0: self.hasFormants = True self.formantPlotCanvas.create_oval( x * (self.plotWidth / PLOTWIDTH) - radius, y * (self.plotHeight / PLOTHEIGHT) - radius, x * (self.plotWidth / PLOTWIDTH) + radius, y * (self.plotHeight / PLOTHEIGHT) + radius, fill=color, tags="userformants") self.xPlotList.append(x) self.yPlotList.append(y) self.prevX = x self.prevY = y if not self.isRecording: if formant != None: pass
def plotFormants(self, sound): probabilityOfVoicing = SoundProcessing.getProbabilityOfVoicing( sound, False) if probabilityOfVoicing == 1.0: formants = SoundProcessing.getFormants(sound, self.gender, False) #Only plot the latest formants of the sound if there's a good chance that it is the user speaking instead of background noise. if formants != None: latestF1 = formants[0] / SCALEDOWN latestF2 = FORMANTPLOTWIDTH - (formants[1] / SCALEDOWN) + XSHIFT + XOFFSET if self.id == 0: latestF2 = latestF2 * 1.5 - 400 latestF1 = latestF1 * 2 - 100 elif self.id == 1: latestF2 = latestF2 * 1.5 - 400 latestF1 = latestF1 * 2.7 - 300 elif self.id == 2: latestF2 = latestF2 * 1.2 - 130 latestF1 = latestF1 * 1.8 - 130 elif self.id == 3: latestF2 = latestF2 * 1.5 - 330 latestF1 = latestF1 * 2.7 - 300 if latestF2 > XSHIFT and latestF1 < FORMANTPLOTHEIGHT - YSHIFT: self.formantPlotCanvas.create_oval(latestF2 - 2, latestF1 - 2, latestF2 + 2, latestF1 + 2, fill='black', tags="userformants") if not self.isRecording: if formants != None: print ""
def loadAudioFile(self): filename = tkFileDialog.askopenfilename(initialdir=self.appDirectory) self.formantPlotCanvas.delete('loadedformants') self.loadedAudio.config(load=filename) self.playLoadButton.config(state='normal') loadedFormants = SoundProcessing.getFormants(self.loadedAudio,self.gender,True) probabilityOfVoicingList = SoundProcessing.getProbabilityOfVoicing(self.loadedAudio,True) self.formantPlotCanvas.delete('loadedformants') #print len(loadedFormants) #print len(probabilityOfVoicingList) try: for i in range(0,len(loadedFormants)): probabilityOfVoicing = probabilityOfVoicingList[i] if probabilityOfVoicing == 1.0: formant = loadedFormants[i] f1 = formant[0]/SCALEDOWN f2 = FORMANTPLOTWIDTH - (formant[1]/SCALEDOWN) + XSHIFT + XOFFSET self.formantPlotCanvas.create_oval(f2-2,f1-2,f2+2,f1+2, fill='red', tags="loadedformants") except IndexError: print ""