I have a USB sound card connecting mic & speakers to a Raspberry Pi Zero W +
The following script plays audio fine when run from the terminal. However, when run from cron, nothing can be heard.
Script:
import simpleaudio as sa
print('playing audio')
wave_obj = sa.WaveObject.from_wave_file('/home/pi/music.wav')
play_obj = wave_obj.play()
play_obj.wait_done()
print('stopped')
Pi user's Cron:
@reboot sleep 5; python3 /home/pi/audio_test.py > /home/pi/audio_test.log
/home/pi/audio_test.log
is created and contains the string 'playing audio', so I know the script is running, but something is obviously going wrong when it comes to actually playing the audio.
Question:
How do I get the python script to play audio at boot without an interactive shell?