respeaker / respeakerd

respeakerd is the server application for the microphone array solutions of SEEED, based on librespeaker which combines the audio front-end processing algorithms.
MIT License
54 stars 24 forks source link

Failed to setschedparam: Operation not permitted #19

Open jmatsushita opened 4 years ago

jmatsushita commented 4 years ago

After installing manually following only these lines from the install script (to not install Alexa related code) https://github.com/respeaker/respeakerd/blob/master/scripts/install_all.sh#L39-L88

Also checking that pulse audio was configured properly, the systemd service failed with

(188ms)DEBUG -- record stream state: 2  [pulse_collector_node.cc:482]
(188ms)INFO  -- Connected to PulseAudio server.  [pulse_collector_node.cc:493]
(189ms)DEBUG -- PulseCollectorNode input: channels 8 rate 48000, output: channels 8 rate 16000  [pulse_collector_node.cc:504]
(189ms)INFO  -- PulseCollectorNode thread started.  [pulse_collector_node.cc:506]
Failed to setschedparam: Operation not permitted
(191ms)INFO  -- PulseCollectorNode thread joined.  [pulse_collector_node.cc:635]
Can not start the respeaker node chain.

Setting

sudo sysctl -w kernel.sched_rt_runtime_us=-1

Fixed the problem, but it is supposed to be a dangerous setting https://access.redhat.com/solutions/1604133

Since librespeaker is not open source as far as I can tell (calling it libre is really misinformation :( ) I can't check what's happening in pulse_collector_node.cc

$ cat /etc/issue.net
Debian GNU/Linux 9

respeaker.io Debian Image 20180801

Support/FAQ: http://respeaker.io

default username:password is [respeaker:respeaker]

$ sudo apt-cache policy librespeaker
librespeaker:
  Installed: 2.1.2-build190110
  Candidate: 2.1.2-build190110
  Version table:
 *** 2.1.2-build190110 500
        500 http://respeaker.seeed.io/deb stretch/main armhf Packages
        100 /var/lib/dpkg/status
     2.1.1-build181119 500
        500 http://respeaker.seeed.io/deb stretch/main armhf Packages
     2.0.0-build180720 500
        500 http://respeaker.seeed.io/deb stretch/main armhf Packages

$ pip freeze
cryptography==1.7.1
enum34==1.1.6
idna==2.2
ipaddress==1.0.17
keyring==10.1
keyrings.alt==1.3
pixel-ring==0.1.0
pulsectl==20.5.1
pyasn1==0.1.9
PyAudio==0.2.11
pycrypto==2.6.1
pydbus==0.6.0
pygobject==3.22.0
pyusb==1.0.2
pyxdg==0.25
SecretStorage==2.3.1
six==1.10.0
spidev==3.5
voice-engine==0.1.3

Possible Solution

Open source librespeaker

sskorol commented 3 years ago

@jmatsushita I faced the same issue while trying to run librespeaker code from within systemd (dedicated service based on this lib).

Checking different forums and SO lead me to the hint about "Realtime Priority" option which equals 99 while running in a normal user-mode. And systemd sets it equal to 0 by default. You can adjust the real-time priority via ulimit -r command from the terminal. However, on a service level, it's called LimitRTPRIO. Anyway, when I added this option to my systemd service, the permission issue has gone. But unfortunately, it wasn't the last one.

Finally, I came up with a bit different approach - creating service via pm2 library (popular process manager). Technically, it's started as a systemd service as well. But I believe the main difference is that it spawns other processes from within itself. I'm not sure about its internals but adding LimitRTPRIO=99 to the pm2 service and configuring my app (based on librespeaker) to be started automatically via pm2 did the trick. You can find details in my voice streaming project.