raspberrypi-ui / piwiz

First-run startup wizard
11 stars 15 forks source link

piwiz chance audio device #20

Closed Blackbox-git closed 3 years ago

Blackbox-git commented 3 years ago

Hello spl237,

I just wanted to say thank you. You have shown me some time ago under the point raspi-config how to set now new the standard output to Headphone. At the same time I have to apologize for my bad English, as I have to use Deepl to translate the text.

I run a Raspberry Pi OS with desktop without mouse and keyboard but with a screen. On the screen the RTSP stream of my PTZ network camera is played via VLC. The sound has to be output via the headphone port. To control my camera I built myself a control unit with an Arduino. Here is a link to the Github repository. https://github.com/JuliaWollner/PTZCameraControlKeypad

The installation of the Raspberry Pi is done headless via a self-made installation script.

When I manually entered the command "pactl set-default-sink 1", the sound output was redirected to the headphone output. After a reboot, however, the sound output was back to HDMI. The switching was not permanent in my opinion.

But now I noticed that your program piwiz outputs sound for visually impaired people. After I renamed this program to "piwiz" without ".desktop", I noticed that the above mentioned command pactl set-default-sink 1" was saved permanently, even after a reboot.

Could it be that your piwiz program keeps resetting the output source to HMDI on its own, and is this behavior intentional?

Additionally I had to increase the basic volume of the headphone connector via the command "amixer -c 1 sset 'headphone' 95%", because this is only possible for the master output via the GUI or my self-made volume button.

However, I still have a problem. If a programme is started by Cron, which is supposed to output an audio signal, then I unfortunately hear nothing via the headphone connection. If I stop the programme and start it manually, the audio output works without problems. Manual playback via the console also works without problems. Do you have any tips for me?

spl237 commented 3 years ago

When I manually entered the command "pactl set-default-sink 1", the sound output was redirected to the headphone output. After a reboot, however, the sound output was back to HDMI. The switching was not permanent in my opinion.

But now I noticed that your program piwiz outputs sound for visually impaired people. After I renamed this program to "piwiz" without ".desktop", I noticed that the above mentioned command pactl set-default-sink 1" was saved permanently, even after a reboot.

Could it be that your piwiz program keeps resetting the output source to HMDI on its own, and is this behavior intentional?

Yes - piwiz does reset the audio output to HDMI whenever it runs if there is an HDMI device available. This is deliberate; the default audio output for the audio prompt would otherwise be the headphone jack, which means no-one would hear it without headphones connected. (If there is no HDMI device available, it should output to the headphone jack.)

You shouldn't have the piwiz wizard running at every boot, though - it should only run at the first boot. Hitting "Cancel" on the first page of the wizard will stop it running again.

However, I still have a problem. If a programme is started by Cron, which is supposed to output an audio signal, then I unfortunately hear nothing via the headphone connection. If I stop the programme and start it manually, the audio output works without problems. Manual playback via the console also works without problems. Do you have any tips for me?

I'm afraid I don't know why that would be happening. But there seem to be reports online of pulseaudio applications not working properly when started by cron, such as https://superuser.com/questions/1207581/pacmd-why-doesnt-it-work-from-cron, and https://askubuntu.com/questions/530048/ubuntu-14-04-and-playing-songs-from-cron - it doesn't look to be a Raspberry Pi specific problem. The second of those links suggests it is a problem with the XDG_RUNTIME_DIR environment setting when running under cron. HTH.

Blackbox-git commented 3 years ago

Hello Simon,

Thanks again for the tip. I have adjusted the programme that is started via cron as follows.

I changed the command "aplay /home/pi/Music/beep.wav" to the command "XDG_RUNTIME_DIR=/run/user/1000 aplay /home/pi/Music/beep.wav".

Now the output is also via headphone when the programme is started via cronjob and not only via console. The start via console still works normally.

Unfortunately, I have another problem. I also have a programme that is started via Systemd. Unfortunately, the adjustment does not work there. Could you perhaps give me another tip on how to get the sound output from this programme to the headphone connection?

Here you can see my written Systemd unit with the name keypad.service.

[Unit]
Description=keypadhandler
After=network-pre.target network.target network-online.target

[Service]
Type=simple
ExecStart=/opt/keypad/keypadhandler.py
Restart=always

[Install]
WantedBy=multi-user.target
spl237 commented 3 years ago

Sorry - no idea about that - I suspect Google can probably tell you!

Blackbox-git commented 3 years ago

I created a workaround which works for me.

I added the criteria "User=pi" to Systemd Service Unit.

In combination with the "XDG_RUNTIME_DIR" the program ouput the sound to the Heasphone connection.