Wednesday, February 2, 2022

[SOLVED] Sound output to bluetooth or usb sound card via python script

Issue

I am just having the hardest time getting sound output from my RPi Zero to either bluetooth or a USB sound card from python script outside of IDE using omxplayer in a subprocess. I have searched and tried various "fixes" without success. Here is an example from the code.

subprocess.Popen (["omxplayer", "--loop", "/home/pi/Desktop/LED_PROJECTS/SoundEffects/candle.mp3"])

I have tried -o, alsa without success (for bluetooth) and -o, alsa:hw:0,1 (for USB sound card). Before giving up, I thought I would ask the question here. Sound just keeps wanting to come out of the HDMI port.


Solution

Okay, I solved it. The above is correct, however, my card number and device number were off. To see list of devices:

aplay -l

From there, find your device and it should work! This was mine:

subprocess.Popen (["omxplayer", "--loop", "-o", "alsa:hw:2,0", "/home/pi/Desktop/LED_PROJECTS/SoundEffects/candle.mp3"])


Answered By - just_dabbling
Answer Checked By - Timothy Miller (WPSolving Admin)