Closed leskerr closed 5 months ago
Issue #136 could be related to this.
I have a branch that uses 'python-sounddevice' instead of 'PyAudio'. Using 'python-sounddevice' resolves the ALSA errors - 'es-33-alsa-errors'.
To try it sounddevice
needs to be installed by running:
python3 -m pip install sounddevice
and soundfile
by running:
python3 -m pip install soundfile
Testing still needs to be done on Windows and Mac. Additional testing also needs to be done on Linux.
@Greg-R it would be great if you could pull branch 'es-33-alsa-errors' and give it a try, but I understand if you want to wait until it is tested and moved into master.
The 'es-33-alsa-errors' branch doesn't update pykob.syscheck
yet. I will work on that later today.
I tried the es-33-alsa-errors
branch on my Linux laptop just now. The first problem I ran into is pip
wasn't installed on my computer. Hard to believe, but true.
les@Whimsy:~/PyKOB/MKOB$ python3 -m pip install sounddevice
/usr/bin/python3: No module named pip
I installed pip
and installed sounddevice
and soundfile
. Then I ran MKOB and tried sending some letters on the keyboard. No more ALSA errors and I did get sound, but it was very sluggish. This resulted in buffer underrun warnings coming from KOB.sounder
.
les@Whimsy:~/PyKOB/MKOB$ python3 MKOB.pyw
2020-09-17 09:17:13 INFO: Load audio file: /usr/local/lib/python3.8/dist-packages/pykob/resources/clack48.wav
2020-09-17 09:17:13 INFO: Load audio file: /usr/local/lib/python3.8/dist-packages/pykob/resources/click48.wav
2020-09-17 09:17:13 INFO: Interface for key and sounder on serial port '/dev/ttyUSB0' not available. Key and sounder will not be used.
2020 9 17 - 9 0001-01-01 00:00:00 14
2020-09-17 09:17:14 INFO: Record to 'Session-20200917-0917.json'
PyKOB 1.2.9
MorseKOB 4.0.11
Circuit Closer True, internet_active was False
KOB.sounder buffer empty: 1.653 -0.07 -60 (-460, 60, -60, 60, -60, 60, -60, 180)
KOB.sounder buffer empty: 1.858 -0.085 -60 (-460, 60, -60, 60, -60, 60, -60, 180)
KOB.sounder buffer empty: 2.039 -0.062 -60 (-460, 60, -60, 60, -60, 60, -60, 180)
I'll try this on Windows later today.
I have a few things on order to patch up my old DCM-6 based KOB circuit to safely interface to a Raspberry Pi. I should have everything today and give it a try this weekend. I have also been upgrading my knowledge of git, in particular working with remote repositories. So I am motivated to pull the branch!
I tried with my Windows laptop and got the same kind of extreme sluggishness from the audio as I did with Linux.
The good news is that the pip install
commands worked right away for sounddevice
and soundfile
.
@leskerr thank you for your testing efforts and your results. I saw the same thing in my Mac testing but wanted to get some other testing results without influencing anything. I didn't see the same on my Linux machine, but good to get that info as well.
There is quite a bit of information about improving performance, but it takes more code, so I wanted to start with a basic implementation first and then work from there as needed.
I was happy to see that it did work (albeit, with performance problems) and it got rid of the ALSA errors (that didn't keep it from working but were very annoying and would concern many users).
I will work on resolving the performance issues.
Updated pykob.syscheck to display python-sounddevice info rather than PyAudio and also added the device (path) to the serial port information listed.
I have tried a few different libraries, but PyAudio still seems to be the best overall choice for cross-platform use.
It seems to be well-documented that on Linux its use results in a number of ALSA error messages unless a lot of system level configuration is done to eliminate them. In most cases they are harmless (there should really be an ALSA option to turn them off). One option is to redirect stderr
to /dev/null
. That cleans up the output so the PyKOB information is easier to see, but of course, that will hide other errors that may be important.
When I run Sample.py, I do hear the simulated sounder through the speakers, but the program produces the following warning messages:
If I try listening to an active wire using the MKOB client, the 'ALSA underrun' message appears over and over again.