首页 > 解决方案 > PyAudio audio output gets very choppy when the buffer size is increased

问题描述

I'm currently trying to implement delayed auditory feedback into this python program so we can use it for our senior design class. The delayed audio part is fine, but when it comes to researching, the delayed effect should "ramp up", i.e. start at 0ms and ramp up to the desired amount like 200ms.

Here are the devices I have set up (the buffer starts at 44 because that is equivalent to 1ms of delay):

try:
    streamIn = device.open(
        format=paFloat32,
        channels=self._CHANNELS,
        rate=self._RATE,
        input=True,
        frames_per_buffer=44
    )

    streamOut = device.open(
        format=paFloat32,
        channels=self._CHANNELS,
        rate=self._RATE,
        output=True,
        frames_per_buffer=44
    )

And then when it comes to streaming the audio, this is what I have (the buffer increases by 44 because every 1ms is an increase to 44 to the buffer):

delayDisplay = 1
count = 0
while self._streamIn.is_active():
    if self._buffer < self._actualBuffer:
        self._buffer = self._buffer + 44
        delayDisplay = delayDisplay + 1
        count = count + 1
    self._trigger.emit(delayDisplay/1000)
    audioData = self._streamIn.read(self._buffer)
    self._streamOut.write(audioData)

It currently works as of now. The audio gets delayed at an increasing rate, but when it gets to about 180ms the audio starts to cut out and get very choppy.
Does anyone know how to fix this, if there is a solution for it.

标签: pythonaudiostreambufferpyaudio

解决方案


推荐阅读