Raspberry Pi上的crontab无法播放音频 [英] Audio doesn't play with crontab on Raspberry Pi

查看:86
本文介绍了Raspberry Pi上的crontab无法播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取Raspberry Pi,该Raspberry Pi当前已连接到蓝牙扬声器,以按计划在每天更新我的 cron 工作的基础上播放音频文件 @daily 获取新的时间安排(基本上是祈祷)

I'm trying to get my Raspberry Pi which is currently connect to a bluetooth speaker to play an audio file daily on a schedule basis where my cron job is being update @daily to get new timing (It's basically a call to prayer)

crontab- l

@daily /home/pi/athan/update_prayers.sh
39 05 27 2 * /home/pi/athan/call_prayer.sh >/dev/null 2>&1 #fajr
31 12 27 2 * /home/pi/athan/call_prayer.sh >/dev/null 2>&1 #dhuhr
34 15 27 2 * /home/pi/athan/call_prayer.sh >/dev/null 2>&1 #asr
05 18 27 2 * /home/pi/athan/call_prayer.sh >/dev/null 2>&1 #maghrib
24 19 27 2 * /home/pi/athan/call_prayer.sh >/dev/null 2>&1 #isha

所以,以上就是我现在所拥有的,这是 /home/pi/athan/update_prayers.sh

So, the above is what I have right now and this is the content of /home/pi/athan/update_prayers.sh

#!/bin/bash
/home/pi/.nvm/versions/node/v7.5.0/bin/node /home/pi/athan/set_prayer.js

基本上是我的 set_prayer。 js 只是在使用 https://www.npmjs.com/package/ crontab 模块来设置crontab,我每天都能获取它更新,在这里没有问题。现在我正在使用 Mplayer 播放音频,这是我使用的命令:

Basically my set_prayer.js is just using this https://www.npmjs.com/package/crontab module to set crontab and I was able to get it update daily no problem here. Right now I'm using Mplayer to play the audio and this is the command I use:

/home/pi/athan/call_prayer.sh

#!/bin/bash
/usr/bin/mplayer /home/pi/athan/athan.mp3

我的这里的问题是,当cron作业运行时,没有声音,或者我什至不知道该作业是否正在运行,但是当我手动执行时,我可以听到播放音频的问题。我也尝试使用 / usr / bin / omxplayer -o alsa /home/pi/athan/athan.mp3 在这里直接运行它,而不是运行bash脚本和它似乎不适用于cron,但是当我直接运行命令时可以正常工作。

My problem here is that when it's time for the cron job to run there's no sound or I don't even know if the job is being run, but when I do it manually I can hear the audio being played no problem. I've also tried to run it directly here using /usr/bin/omxplayer -o alsa /home/pi/athan/athan.mp3 instead of running bash script and it doesn't seem to work with cron but works fine when I run the command directly.

推荐答案

我正在努力解决类似的问题(如果该命令是从crontab运行的,则蓝牙扬声器上没有音频。

I was struggling with a similar problem (no audio on Bluetooth speaker if the command is run from crontab.

问题是混合pulseaudio / crontab和环境设置。

The problem was the mix pulseaudio/crontab and the environment setup.

以下解决方案为我工作:
https://wiki.archlinux.org/index.php/PulseAudio#Play_sound_from_a_non-interactive_shell_.28systemd_service.2C_cron.29

The following solution worked for me: https://wiki.archlinux.org/index.php/PulseAudio#Play_sound_from_a_non-interactive_shell_.28systemd_service.2C_cron.29

so基本上只需执行 crontab -e 并添加以下内容:

so basically just do crontab -e and add the following:

XDG_RUNTIME_DIR=/run/user/user_id

可以找到用户ID通过以下命令:

the user id can be found out by the following command:

id [user_name]

这篇关于Raspberry Pi上的crontab无法播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆