https://teratail.com/questions/188667
上記の関連になります。
複数のRaspberryPiで実施したいと思い、
Raspberry PiとRGBマトリクスパネルを用いてUSBオーディオから音を鳴らしたいです。
が、音が前回同様鳴らない状態です。
・環境
Raspberry Pi Model 3 B+
Python 3
以下オーディオ関連で確認した内容です。
pi@raspberrypi:~ $ aplay -l **** ハードウェアデバイス PLAYBACK のリスト **** カード 1: Device [USB PnP Sound Device], デバイス 0: USB Audio [USB Audio] サブデバイス: 1/1 サブデバイス #0: subdevice #0 pi@raspberrypi:~ $ sudo vi /usr/share/alsa/alsa.conf defaults.ctl.card 1 defaults.pcm.card 1 sudo vi /boot/config.txt # Enable audio (loads snd_bcm2835) dtparam=audio=off pi@raspberrypi:~ $ cat /proc/asound/modules 1 snd_usb_audio
以下ソースコードになります。
Python
1#!/usr/bin/env python3 2# coding: UTF-8 3# Display a runtext with double-buffering. 4from samplebase import SampleBase 5from rgbmatrix import graphics 6from datetime import datetime 7import time 8from logging import getLogger, StreamHandler, DEBUG 9 10import subprocess 11 12logger = getLogger(__name__) 13handler = StreamHandler() 14handler.setLevel(DEBUG) 15logger.setLevel(DEBUG) 16logger.addHandler(handler) 17 18# 音をだすクラス 19class SoundClass: 20 # 音を再生 21 def sound_play(self): 22 subprocess.call("aplay /home/pi/Desktop/rpi-rgb-led-matrix/bindings/python/samples/sound.wav", shell=True) 23 24class RunText(SampleBase): 25 26 # コンストラクタ 27 def __init__(self, *args, **kwargs): 28 super(RunText, self).__init__(*args, **kwargs) 29 self.parser.add_argument("-t", "--text", help="The text to scroll on the RGB LED panel", default="21:52") 30 31 # 音を再生 32 # ★★★ 33 sound_class = SoundClass() 34 sound_class.sound_play() 35 36 def run(self): 37 # LEDパネルに描画するcanvasを作成 38 offscreen_canvas = self.matrix.CreateFrameCanvas() 39 font = graphics.Font() 40 41 # フォントを読み込み 42 font.LoadFont("../../../fonts/10x20.bdf") 43 # 出力する文字の色を設定 44 textColor = graphics.Color(100, 100, 255) 45 46 sound_class = SoundClass() 47 48 while True: 49 # 現在時刻を取得 50 now_time = datetime.now() 51 52 # 秒のみ取得 53 s = now_time.second 54 55 # ちょうどの時間に音を出す 56 if s == 00: 57 # メソッド呼び出し 58 # ■■■ 59 sound_class.sound_play() 60 61 logger.debug(now_time.strftime('%M:%S')) 62 offscreen_canvas.Clear() 63 graphics.DrawText(offscreen_canvas, font, 6, 22, textColor, now_time.strftime('%M:%S')) 64 65 #1秒ごとに実行 66 time.sleep(1) 67 68 #表示する 69 self.matrix.SwapOnVSync(offscreen_canvas) 70 71# Main function 72if __name__ == "__main__": 73 run_text = RunText() 74 75 if (not run_text.process()): 76 run_text.print_help()
・00秒になった時のエラー内容
ALSA lib confmisc.c:767:(parse_card) cannot find card '0' ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_card_driver returned error: そのようなファイルやディレクトリはありません ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_concat returned error: そのようなファイルやディレクトリはありません ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name ALSA lib conf.c:4528:(_snd_config_evaluate) function snd_func_refer returned error: そのようなファイルやディレクトリはありません ALSA lib conf.c:5007:(snd_config_expand) Evaluate error: そのようなファイルやディレクトリはありません ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default aplay: main:788: audio open error: そのようなファイルやディレクトリはありません
ご教授いただけないでしょうか?
回答1件
あなたの回答
tips
プレビュー