How to remove pops from concatented sound data in PyAudio

前端 未结 3 902
失恋的感觉
失恋的感觉 2021-01-06 11:45

How do you remove \"popping\" and \"clicking\" sounds in audio constructed by concatenating sound tonal sound clips together?

I have this PyAudio code for generating

3条回答
  •  鱼传尺愫
    2021-01-06 12:19

    My initial suspicion that the individual waveforms weren't aligning was correct, which I confirmed by inspecting in Audacity. My solution was to modify the code to start and stop each waveform on the peak of the sine wave.

    def tone(self, frequency, length=1000, play=False, **kwargs):
    
        number_of_frames = int(self.bitrate * length/1000.)
    
        record = False
        x = 0
        y = 0
        while 1:
            x += 1
            v = math.sin(x/((self.bitrate/float(frequency))/math.pi))
    
            # Find where the sin tip starts.
            if round(v, 3) == +1:
                record = True
    
            if record:
                self._queue.append(chr(int(v*127+128)))
                y += 1
                if y > number_of_frames and round(v, 3) == +1:
                    # Always end on the high tip of the sin wave to clips align.
                    break
    

提交回复
热议问题