Play WAV Audio in Crontab

Hi All,

Today, I’m going to show how play WAV audio in Crontab raspberry pi.

Step 1 : Install Player

For this tutorial, I’m using mplayer. You can install it by do this command:

$ sudo apt-get update 
$ sudo apt-get install mplayer

Step 2 : Test mplayer

After install the player, you can test to play any wav file (eg: deen.wav) by this command:

$ mplayer /home/pi/deen.wav

Step 3 : Create bash file

After that, we need to create a bash file so that will play the wav file. Create bash file name prayer.sh

$ sudo nano prayer.sh 

Put this coding in prayer.sh file.

$ #!/bin/bash
export XDG_RUNTIME_DIR=/run/user/1000
/usr/bin/mplayer /home/pi/deen.wav

Step 4 : Make the bash file executable

Type the command below:

$ sudo chmod +x prayer.sh 

Step 5 : Go to crontab

Type the command below (without sudo):

$ crontab -e

Put this coding in prayer.sh file. (It will run the bash file named prayer.sh at any 15 minutes)

$ 15 * * * * /home/pi/prayer.sh

or you can run at reboot by this command in crontab.

$ @reboot /home/pi/prayer.sh

Done !!!!