def drawSpectra(self, data, samplerate): leftData, rightData = utils.channels(data) leftPoints, rightPoints = [], [] width, _ = self.windowSize # buffer left/right data self.leftBuffer.add(leftData) if (self.leftBuffer.filled): leftSpectrum = self.buildSpectrum(self.leftBuffer.data) # slicing the data breaks pitch dection outside of the window. # (full range of the fft bins. doesn't have to fall inside the window.) leftSpectrum = self.avgLeft.average(leftSpectrum) leftPoints = self.drawSpectrum(leftSpectrum) freq = self.calcFreq(leftSpectrum, samplerate) self.printText( "L Freq: {0:.2f}Hz {1}".format(freq, audio.pitch(freq)), 0, self.leftcolor) self.rightBuffer.add(rightData) if (self.rightBuffer.filled): rightSpectrum = self.buildSpectrum(self.rightBuffer.data) rightSpectrum = self.avgRight.average(rightSpectrum) rightPoints = self.drawSpectrum(rightSpectrum) freq = self.calcFreq(rightSpectrum, samplerate) self.printText( "R Freq: {0:.2f}Hz {1}".format(freq, audio.pitch(freq)), 1, self.rightcolor) return leftPoints, rightPoints
def slow_down(track): """Slows down the track""" rate = random.uniform(*config.SLOW_DOWN_RANGE) return audio.pitch(track, round(rate, 2))
def speed_up(track): """Speeds up the track""" rate = random.uniform(*config.SPEED_UP_RANGE) return audio.pitch(track, round(rate, 2))