Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3862

Python • Re: Running PyAudio Script On Startup Issue

$
0
0
I just type what sashib said:

Code:

sudo systemctl start audio_recorder.service
Here is what the journal said when I ran my script:

Code:

Aug 19 10:06:26 raspberrypi systemd[1]: Started audio_recorder.service - run audio script on boot.Aug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slaveAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rearAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfeAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.sideAug 19 10:06:28 raspberrypi python3[719]: ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.hdmi.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'Aug 19 10:06:28 raspberrypi python3[719]: ALSA lib conf.c:5180:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryAug 19 10:06:28 raspberrypi python3[719]: ALSA lib conf.c:5703:(snd_config_expand) Evaluate error: No such file or directoryAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM hdmiAug 19 10:06:28 raspberrypi python3[719]: ALSA lib confmisc.c:1369:(snd_func_refer) Unable to find definition 'cards.0.pcm.hdmi.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'Aug 19 10:06:28 raspberrypi python3[719]: ALSA lib conf.c:5180:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directoryAug 19 10:06:28 raspberrypi python3[719]: ALSA lib conf.c:5703:(snd_config_expand) Evaluate error: No such file or directoryAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM hdmiAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modemAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modemAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phonelineAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm.c:2666:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phonelineAug 19 10:06:28 raspberrypi python3[719]: Cannot connect to server socket err = No such file or directoryAug 19 10:06:28 raspberrypi python3[719]: Cannot connect to server request channelAug 19 10:06:28 raspberrypi python3[719]: jack server is not running or cannot be startedAug 19 10:06:28 raspberrypi python3[719]: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlockAug 19 10:06:28 raspberrypi python3[719]: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlockAug 19 10:06:28 raspberrypi python3[719]: Cannot connect to server socket err = No such file or directoryAug 19 10:06:28 raspberrypi python3[719]: Cannot connect to server request channelAug 19 10:06:28 raspberrypi python3[719]: jack server is not running or cannot be startedAug 19 10:06:28 raspberrypi python3[719]: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlockAug 19 10:06:28 raspberrypi python3[719]: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlockAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dspAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dspAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refusedAug 19 10:06:28 raspberrypi python3[719]: ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refusedAug 19 10:06:30 raspberrypi python3[719]: ALSA lib pcm_a52.c:1001:(_snd_pcm_a52_open) a52 is only for playbackAug 19 10:06:31 raspberrypi python3[719]: ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field cardAug 19 10:06:31 raspberrypi python3[719]: ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'Aug 19 10:06:31 raspberrypi python3[719]: ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field cardAug 19 10:06:31 raspberrypi python3[719]: ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'Aug 19 10:06:31 raspberrypi python3[719]: ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slaveAug 19 10:06:31 raspberrypi python3[719]: ALSA lib pcm_dmix.c:999:(snd_pcm_dmix_open) unable to open slaveAug 19 10:06:31 raspberrypi python3[719]: Cannot connect to server socket err = No such file or directoryAug 19 10:06:31 raspberrypi python3[719]: Cannot connect to server request channelAug 19 10:06:31 raspberrypi python3[719]: jack server is not running or cannot be startedAug 19 10:06:31 raspberrypi python3[719]: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlockAug 19 10:06:31 raspberrypi python3[719]: JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlockAug 19 10:15:24 raspberrypi systemd[1]: Stopping audio_recorder.service - run audio script on boot...Aug 19 10:15:25 raspberrypi systemd[1]: audio_recorder.service: Deactivated successfully.Aug 19 10:15:25 raspberrypi systemd[1]: Stopped audio_recorder.service - run audio script on boot.Aug 19 10:15:25 raspberrypi systemd[1]: audio_recorder.service: Consumed 2.335s CPU time.
Any ideas on how to fix?
By the way, I have a different OS installed. I have Rpi OS 64-Bit (the one it recommends) and yes, it's Bookworm, running PulseAudio.

That contradicts what you said above:
Also, when I run the .service file just from terminal, it works,
Is that log from auto starting or from manually starting the service?

That log shows something trying to use ALSA and jack.

As you now say you're running Bookworm are you 101% certain that you're using PulseAudio? The default is Pipewire so if you didn't change that in raspi-config that's what you'll be using unless your python code (or a module it relies on has installed and) is using something else.

You may want to try the following to determine if the problem is within your code or not:
  • Disable your current service:

    Code:

    sudo systemctl disable audio_recorder.service
  • Create the following service:

    Code:

    [Unit]Description=aplay root test[Service]ExecStart=aplay /usr/share/sounds/alsa/Front_Center.wav[Install]WantedBy=multi-user.target
  • Copy it to /etc/systemd/system
  • Enable it:

    Code:

    sudo systemctl enable service-name
  • Reboot
  • Check the service status and the journal for errors.
If you hear audio the problem is in your code or the modules/libraries you're using. Both aplay and /usr/share/sounds/alsa/Front_Center.wav are part of the RPiOS installation. My results when testing with this can be found here: viewtopic.php?t=375250

Be aware that the audio file only has sound on one channel.

I'm stepping back from this thread again as I really don't have a clear idea of what you're doing and what is happening. And getting that from you so far has been like getting blood from a stone.

Statistics: Posted by thagrol — Wed Aug 21, 2024 10:21 pm



Viewing all articles
Browse latest Browse all 3862

Trending Articles