bastibe / SoundCard

A Pure-Python Real-Time Audio Library
https://soundcard.readthedocs.io
BSD 3-Clause "New" or "Revised" License
680 stars 69 forks source link

Can't use it on Raspberry Pi #116

Closed josephernest closed 3 years ago

josephernest commented 3 years ago

Hello, When doing import soundcard on a Raspberry Pi (RaspiOS Buster image "2020-08-20-raspios-buster-armhf-lite.zip", Python 3.7.3, numpy already installed), it blocks and never returns, so I have to CTRL+C to stop it:

>>> import soundcard
Python 3.7.3^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.7/site-packages/soundcard/__init__.py", line 4, in <module>
    from soundcard.pulseaudio import *
  File "/home/pi/.local/lib/python3.7/site-packages/soundcard/pulseaudio.py", line 259, in <module>
    _pulse = _PulseAudio()
  File "/home/pi/.local/lib/python3.7/site-packages/soundcard/pulseaudio.py", line 71, in __init__
    time.sleep(0.001)
KeyboardInterrupt

Do you know the reason why doing just import soundcard makes it enter an infinite loop time.sleep(0.001) @bastibe?

All the best

Chum4k3r commented 3 years ago

It fails to find PulseAudio and initialize it. Do you have it installed and running when importing soundcard?

josephernest commented 3 years ago

This solved it indeed! I used it on Windows exclusively and as it worked out-of-the-box, I thought it would be the same with Linux / Raspberry Pi. Installing PulseAudio and doing pulseaudio -D was necessary as well.

Thanks!

bastibe commented 3 years ago

Desktop Linux typically has pulseaudio installed and configured by default. Apparently, Raspbian does not. Thank you for reporting, and figuring out your problem.

If you would like, I'd be grateful for a pull request that adds a note about running it on a Raspberry Pi in the readme (probably under an FAQ heading).

josephernest commented 3 years ago

Good idea @bastibe. Added here: https://github.com/bastibe/SoundCard/pull/117