7

I am working on a project that involves recording from a mic on a raspberry pi. for now i am getting this error while the program is running.

python3: src/hostapi/alsa/pa_linux_alsa.c:3641: PaAlsaStreamComponent_BeginPolling: Assertion `ret == self->nfds' failed. Aborted

while searching for ways to fix this, i figured out the file pa_linux_alsa.c belongs to port audio. please refer to the following links.

modified pa_linux_alsa.c i think

how to install port audio

download link

first link is about the error and a modified fix, still dont know where to copy and the last two are about installing portaudio. apparently there is no easier way to install this with a command.

i downloaded the pa_snapshot enhanced version of it. but i dont know where i am supposed to put these files to begin to configure and make as in the readme. I copied the portaudio directory in to home/pi (in the user i think. "cd" and copied it there) then did as in the readme and rebooted the system. i dont see any changes in the error in program. i tried using the command whereis with pa_linux_alsa.c. that command also doesn't show the file or anything related to portaudio.

Eshaka
  • 974
  • 1
  • 14
  • 38

1 Answers1

10

Your first link correctly identifies a bug in portaudio, but the fix is incomplete. I forked the portaudio library and created a patch to fix this. Here are the steps to remove the portaudio package and compile the patched version from source:

sudo apt-get remove libportaudio2
sudo apt-get install libasound2-dev
git clone -b alsapatch https://github.com/gglockner/portaudio
cd portaudio
./configure && make
sudo make install
sudo ldconfig
cd ..

At this point, you should have a patched portaudio library, based on the pa_stable_v190600_20161030 tag. Finally, if you need the PyAudio package for Python, then install it using pip: sudo pip3 install pyaudio.

Greg Glockner
  • 5,433
  • 2
  • 20
  • 23
  • 2
    commit 80aafc6 (i.e. tip of your `alsapatch` branch) seems to unnecessarily remove a lot of error handling. I submitted a tidier version of the [patch to the portaudio mailing list](https://lists.columbia.edu/pipermail/portaudio/2019-July/001888.html) which might be preferable – Sam Mason May 12 '20 at 14:29
  • 1
    Does anyone know if this has been fully addressed/solved upstream already? – matanster Jun 08 '20 at 18:36
  • 3
    I've just noticed that [Debian is pulling in my patch](https://sources.debian.org/patches/portaudio19/19.6.0-1.1/944509-crash.patch/) now. Hence using package version 19.6.0-1.1 (or later) would presumably fix it on Debian. Ubuntu doesn't seem to have picked it up yet, and I can't test because I'm using Arch these days – Sam Mason Aug 17 '20 at 09:02
  • 2
    [Looks like](https://launchpad.net/ubuntu/+source/portaudio19/19.6.0-1.1/+publishinghistory) it made it into the next Ubuntu release, [if I'm looking properly](https://askubuntu.com/questions/1277958/package-integration-process-from-debian-case-in-point-portaudio). – matanster Sep 26 '20 at 17:05
  • From what I can see a fix for this (switching the assertion to at least better error handling) was merged with this pull request https://github.com/PortAudio/portaudio/pull/344 on 18. December 2020 – Daniel Jour Jan 22 '22 at 13:07
  • This post needs more up-votes. The first post I've seen for this specific issue that actually works. – sparkitny Nov 07 '22 at 03:37