Bug 2238746 - playing sounds with pyaudio sometimes hangs
Summary: playing sounds with pyaudio sometimes hangs
Keywords:
Status: CLOSED WORKSFORME
Alias: None
Product: Fedora
Classification: Fedora
Component: pyaudio
Version: 38
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Christian Krause
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2023-09-13 13:07 UTC by Mike FABIAN
Modified: 2024-03-04 04:25 UTC (History)
2 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2023-11-04 09:56:16 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)
pyaudio-test-trigger-hang.py (704 bytes, text/plain)
2023-09-13 13:07 UTC, Mike FABIAN
no flags Details

Description Mike FABIAN 2023-09-13 13:07:19 UTC
After updating pyaudio to 0.2.13 using this update:
https://bodhi.fedoraproject.org/updates/FEDORA-2023-f675d09ee6

With the updated python3-pyaudio, it works but not reliably. It sometimes hangs, pretty often actually.

The attached script makes it rather easy to reproduce the hang. It should do 99 beeps, but does the full amount of beeps not always, quite often it hangs like this:

    $ python3 ~/tmp/audio-test/pyaudio-test-trigger-hang.py 
    ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.front.0:CARD=0'
    ALSA lib conf.c:5181:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5704:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM front
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
    ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.surround51.0:CARD=0'
    ALSA lib conf.c:5181:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5704:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM surround21
    ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.surround51.0:CARD=0'
    ALSA lib conf.c:5181:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5704:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM surround21
    ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.surround40.0:CARD=0'
    ALSA lib conf.c:5181:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5704:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM surround40
    ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.surround51.0:CARD=0'
    ALSA lib conf.c:5181:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5704:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM surround41
    ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.surround51.0:CARD=0'
    ALSA lib conf.c:5181:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5704:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM surround50
    ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.surround51.0:CARD=0'
    ALSA lib conf.c:5181:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5704:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM surround51
    ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.surround71.0:CARD=0'
    ALSA lib conf.c:5181:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5704:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM surround71
    ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
    ALSA lib conf.c:5181:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5704:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM iec958
    ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
    ALSA lib conf.c:5181:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5704:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM spdif
    ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
    ALSA lib conf.c:5181:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
    ALSA lib conf.c:5704:(snd_config_expand) Evaluate error: No such file or directory
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM spdif
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
    ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
    ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave


and here at this `ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slave` message it hangs, there is no more sound and the script never finishes.

I can stop it here with Control-C only because I added:

    # Make Control-C work when it hangs:
    signal.signal(signal.SIGINT, signal.SIG_DFL)

to the script.

When it hangs, stopping the script with Control-C and starting it again, usually reproduces the hang immediately.

Using

    aplay /usr/share/ibus-typing-booster/data/coin9.wav

in a different terminal while this test script is hanging does not work, aplay then hangs as well.

But after stopping the test script with Control-C, running

    aplay /usr/share/ibus-typing-booster/data/coin9.wav

once seems to "fix" the problem, aplay produces the correct sound and the next run of the test script usually works as well.



Reproducible: Always

Comment 1 Mike FABIAN 2023-09-13 13:07:56 UTC
Created attachment 1988650 [details]
pyaudio-test-trigger-hang.py

Test script to reproduce the problem.

Comment 2 Mike FABIAN 2023-09-13 13:10:37 UTC
Comment copied from: https://bugzilla.redhat.com/show_bug.cgi?id=2238132#c12

Christian Krause> I can reproduce similar issues (see below). Anyway, I suggest a new bug report as well. Let's keep using this one for the update and fixing the issue that the package didn't work at all.
Christian Krause> 
Christian Krause> Just to double-check: Do you see the same issues with your own local builds of pyaudio?
Christian Krause> 
Christian Krause> > I can quite easily reproduce the hang using your latest build on Fedora 38:
Christian Krause> > https://koji.fedoraproject.org/koji/buildinfo?buildID=2287903
Christian Krause> 
Christian Krause> A few notes from my tests:
Christian Krause> - works worse if there are other active audio players (e.g. a browser): lots of stutter, sometimes hanging pyaudio
Christian Krause> - I tried using mpg123 with portaudio plugin (to test the underlying portaudio library): issues couldn't be reproduced

Comment 3 Christian Krause 2023-10-04 20:12:36 UTC
Hi @mfabian 

I did a little bit of investigation:

In many examples the open call to create a stream used an additional parameter: "frames_per_buffer" (reference: https://www.portaudio.com/docs/v19-doxydocs/portaudio_8h.html#a443ad16338191af364e3be988014cbbe). The value should correspond with the number of frames which are read (and written) at the same time. So in the example you attached to the bug report, try something like this:

    stream = p.open(
        format=p.get_format_from_width(wf.getsampwidth()),
        channels=wf.getnchannels(),
        rate=wf.getframerate(),
        output=True,
        frames_per_buffer=1024
    )

For me, that fixed it. Please let me know whether it solves the issue on your side as well.

Comment 4 Christian Krause 2023-11-04 09:56:16 UTC
Most likely the problem is fixed by a slightly different usage of the API of pyaudio (see comment #3). Since there was no feedback since a month, I'll close the bug as WORKSFORME now.

Comment 5 Red Hat Bugzilla 2024-03-04 04:25:02 UTC
The needinfo request[s] on this closed bug have been removed as they have been unresolved for 120 days


Note You need to log in before you can comment on or make changes to this bug.