bastibe / SoundCard

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

pluseaudio.py line 3 `import collections` set --> `import collections.abc as collections` #174

Closed yueguobin closed 1 year ago

yueguobin commented 1 year ago

One question

I'm using the KDE Desktop widget PANON, but it doesn't run.

Using debug found a problem:

10月 21 01:25:45 guobin.localhost plasmashell[7436]: qml:
10月 21 01:25:45 guobin.localhost plasmashell[7436]: qml: Traceback (most recent call last):
                                                        File "<frozen runpy>", line 198, in _run_module_as_main
                                                        File "<frozen runpy>", line 88, in _run_code
                                                        File "/home/yueguobin/.local/share/plasma/plasmoids/panon/contents/scripts/panon/backend/client.py", line 53, in <module>
                                                          spectrum_source = source.SoundCardSource(spectrum.NUM_CHANNEL, sample_rate, arguments['--device-index'], cfg_fps)
                                                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                                                        File "/home/yueguobin/.local/share/plasma/plasmoids/panon/contents/scripts/panon/backend/source.py", line 113, in __init__
                                                          self.start()
                                                        File "/home/yueguobin/.local/share/plasma/plasmoids/panon/contents/scripts/panon/backend/source.py", line 172, in start
                                                          stream.__enter__()
                                                        File "/home/yueguobin/.local/share/plasma/plasmoids/panon/contents/scripts/soundcard/pulseaudio.py", line 638, in __enter__
                                                          if isinstance(self.channels, collections.Iterable):
                                                                                       ^^^^^^^^^^^^^^^^^^^^
                                                      AttributeError: module 'collections' has no attribute 'Iterable'

PANON uesd a SOUNDCARD pluseaudio.py

https://stackoverflow.com/questions/72032032/importerror-cannot-import-name-iterable-from-collections-in-python

collections.Iterable don't work

pluseaudio.py line 3 import collections set --> import collections.abc as collections

collections.Iterable is ok

My python version 3.11.5

bastibe commented 1 year ago

Thank you for the bug report. There was a recent fix for the linux version, but not yet for Windows and macOS, and I haven't had time to work on this yet.

If you'd like to help, I'd be grateful for a pull request.

yueguobin commented 1 year ago

173

This has been fixed. I posted duplicate issues

bastibe commented 1 year ago

This has been fixed

It's only fixed on Linux. On macOS and Windows, it is still a problem.

yueguobin commented 1 year ago

on macOS and Windows.

I think it can run.

Because collections.abc is the standard library for Python, Starting with Python 3.3.

But I don't have macOS, on windwos, When I have free time, I can try it.

bastibe commented 1 year ago

I tried running it on macOS today, but had to learn that soundcard actually doesn't run on ARM macOS any more, because Apple apparently requires all audio-accessing apps to ask for permission, and we don't. However, we also can't, because that appears to be an Objective-C function, which is not available to us humble C programmers.

I sincerely hope that these findings are incorrect, that I missed something somewhere. Because if not, soundcard is essentially dead on macOS unless we expand our scope to call Objective-C code somewhere, somehow.

yueguobin commented 1 year ago

I'm a network engineer and know some Python, but I've never learned Objective-C. Couldn't help.

bastibe commented 1 year ago

If you'd like to take a stab at it, I'd be grateful for the help! Obj-C is actually a fun language to play with, and not particularly hard to understand. It's just that we currently only interact with the C layer of coreaudio, and I don't actually know what exactly is needed to make this work again.