python - 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.
解决方案
推荐阅读
- angular5 - Angular 多个 rest api 请求
- laravel - 未找到 Laravel 视图 - 清除每个缓存后
- java - Android 应用和数据库通信:JSON 解析和列表视图
- bash - 单行 bash 命令,将计算并显示文件中特定字符串的出现次数
- node.js - 无法向对话流发送响应
- php - Laravel 多控制器功能一条路线
- pandas - 将数据保存到现有文件中的工作表时在 openpyxl 中正确使用 load_workbook
- sql - XML 元素位置无效。(SQL-XSD)
- elixir - 如何为 Elixir 结构验证/强制执行类型和值?
- c# - 锁定孩子的旋转,使其始终朝下