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

3.5 Compatibility #46

Closed dkumor closed 5 years ago

dkumor commented 5 years ago

EDIT: No longer WIP, the issue described here disappeared after switching to different system.

This is a work in progress attempting to get SoundCard working with Python 3.5, fixing #45.

The reason this specific version is important is because the Raspberry Pi is stuck at 3.5, since it is based on debian stable. I am working on code that uses SoundCard, but must also work on the Pi.

Thus far, I have replaced all f-strings with explicit format statements and removed underscores from numbers. This makes python 3.5 stop complaining about syntax errors, and makes microphone work.

Unfortunately, there is something wrong with media playback on 3.5. I tried the following:

import soundcard
mic = soundcard.default_microphone()
s = soundcard.default_speaker()
r = mic.record(5*44100,44100)
s.play(r,44100)

With a manually compiled 3.7 on the Pi it works without issue, but the default 3.5 gives the following error:

Assertion 's' failed at pulse/stream.c:1399, function pa_stream_connect_playback(). Aborting.

This means that the pull request is not ready for merging - I am currently unsure why the error above shows up for 3.5 but not 3.7, but am hopeful that it is something easy to fix.

dkumor commented 5 years ago

The issue I had was specific to that system - I created a debian stretch VM, and all tests pass successfully there: image

dkumor commented 5 years ago

I have tested the code on windows and linux with Python 3.5 - everything works without issue. I was unable to test on mac, since I don't own one. However, mac files were untouched (I did not find any incompatible syntax in them).

While the library works in windows when manually testing, the unit tests do not pass on windows, due to a TypeError complaining about WSAPI channels. To the best of my knowledge, this is a problem of the original library, and not of my modifications, since the same issue shows up in 3.7 on windows without my modifications. Furthermore, my changes only affect format strings there. I will happily provide more details if requested.

@bastibe - What do you think? Even without changing the setup.py compatible versions, one can still pip install it on 3.5, and this PR will allow it to work there (on both windows and linux, but should also work on mac).

bastibe commented 5 years ago

Cool, thank you! Could you add the version change to setup.py as well, then I'll merge!

dkumor commented 5 years ago

Done!

dkumor commented 5 years ago

Oops, I think I misunderstood: did you want me to update the python_requires? I can undo the change if you wanted 0.2.2 -> 0.2.3

bastibe commented 5 years ago

Perfect, thank you!