Raspberry Piで時報

Raspbian GNU/Linux 11 (bullseye) をインストール

スピーカーを接続

デバイス番号の確認
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
Subdevices: 7/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7
card 1: vc4hdmi [vc4-hdmi], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: MicroII [Audio Advantage MicroII], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0

もし,まだaplayがインストールされてないときは sudo apt install alsa-utils

SPジャック使用ならcard 0,device 0 なので
aplay -D plughw:0,0 /usr/share/sounds/alsa/Front_Center.wavで音が出るのを確認。
USBスピーカ使用ならcard 2,device 0 なので
aplay -D plughw:2,0 /usr/share/sounds/alsa/Front_Center.wavで音が出るのを確認。

時報発生用Shell

[/home/ユーザー名/jihou.sh] の内容 (SPジャック使用の場合)
#!/bin/bash
/usr/bin/aplay/ -D plughw:0,0 /home/ユーザー名/jihou/`date +%H%M.wav`

[crontab -e] の設定

*/30 8-23 * * * /home/ユーザー名/jihou.sh #8時から23時半の間30分ごとにjihou.sh起動

「〇〇時0分です」または「〇〇時30分です」の音声データの用意

[/home/ユーザー名/jihou]ディレクトリーには「〇〇時0分です」または「〇〇時30分です」の音声データを格納 ====> VoiceVOX(https://voicevox.hiroshiba.jp/):四国めたんを使用

$ ls -l /home/xxxxx/jihou
-rw-r–r– 1 xxxxx xxxxx 66604 Aug 13 11:15 0800.wav
-rw-r–r– 1 xxxxx xxxxx 74796 Aug 13 11:15 0830.wav
-rw-r–r– 1 xxxxx xxxxx 59436 Aug 13 11:15 0900.wav
-rw-r–r– 1 xxxxx xxxxx 68140 Aug 13 11:15 0930.wav
-rw-r–r– 1 xxxxx xxxxx 64556 Aug 13 11:15 1000.wav
-rw-r–r– 1 xxxxx xxxxx 73772 Aug 13 11:15 1030.wav
-rw-r–r– 1 xxxxx xxxxx 78892 Aug 13 11:15 1100.wav
-rw-r–r– 1 xxxxx xxxxx 87084 Aug 13 11:15 1130.wav
-rw-r–r– 1 xxxxx xxxxx 70188 Aug 13 11:15 1200.wav
-rw-r–r– 1 xxxxx xxxxx 79404 Aug 13 11:15 1230.wav
-rw-r–r– 1 xxxxx xxxxx 75820 Aug 13 11:15 1300.wav
-rw-r–r– 1 xxxxx xxxxx 84524 Aug 13 11:15 1330.wav
-rw-r–r– 1 xxxxx xxxxx 72236 Aug 13 11:15 1400.wav
-rw-r–r– 1 xxxxx xxxxx 81452 Aug 13 11:15 1430.wav
-rw-r–r– 1 xxxxx xxxxx 70700 Aug 13 11:15 1500.wav
-rw-r–r– 1 xxxxx xxxxx 79404 Aug 13 11:15 1530.wav
-rw-r–r– 1 xxxxx xxxxx 74796 Aug 13 11:15 1600.wav
-rw-r–r– 1 xxxxx xxxxx 84012 Aug 13 11:15 1630.wav
-rw-r–r– 1 xxxxx xxxxx 77356 Aug 13 11:15 1700.wav
-rw-r–r– 1 xxxxx xxxxx 86060 Aug 13 11:15 1730.wav
-rw-r–r– 1 xxxxx xxxxx 78380 Aug 13 11:15 1800.wav
-rw-r–r– 1 xxxxx xxxxx 87084 Aug 13 11:15 1830.wav
-rw-r–r– 1 xxxxx xxxxx 70700 Aug 13 11:15 1900.wav
-rw-r–r– 1 xxxxx xxxxx 89132 Aug 13 19:01 1902.wav
-rw-r–r– 1 xxxxx xxxxx 79916 Aug 13 11:15 1930.wav
-rw-r–r– 1 xxxxx xxxxx 69164 Aug 13 11:15 2000.wav
-rw-r–r– 1 xxxxx xxxxx 78892 Aug 13 11:15 2030.wav
-rw-r–r– 1 xxxxx xxxxx 81964 Aug 13 11:15 2100.wav
-rw-r–r– 1 xxxxx xxxxx 90156 Aug 13 11:15 2130.wav
-rw-r–r– 1 xxxxx xxxxx 75308 Aug 13 11:15 2200.wav
-rw-r–r– 1 xxxxx xxxxx 84012 Aug 13 11:15 2230.wav
-rw-r–r– 1 xxxxx xxxxx 80428 Aug 13 11:15 2300.wav
-rw-r–r– 1 xxxxx xxxxx 89132 Aug 13 11:15 2330.wav

コメント