'Why does my Python code only play sound through my Bluetooth speaker in the IDE, but not the console?
I'm trying to make a soundboard with my Raspberry Pi 3B+ on the latest version of Raspberry Pi OS (as of 5/1/22), but I'm running into a pretty big issue. My goal with this program is to run it headless, and have it output sound to a Bluetooth speaker. The problem is that the only time it works is when I run the code in the IDE (Thonny). I tried to force PyGame to use the Bluetooth speaker mixer.init(devicename = 'TYLT')
but it still didn't work. My code is listed below:
from pygame import mixer
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(10, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(15, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
mixer.init(devicename = 'TYLT')
mixer.music.load('/home/gerson/Downloads/bleep.ogg')
mixer.music.play()
while True: # Run forever
if GPIO.input(10) == GPIO.HIGH:
mixer.music.unpause()
else:
mixer.music.pause()
Any help is appreciated, as I've spent about 3 days trying to figure this out.
Solution 1:[1]
Have you tried other file formats than .ogg? In this post, using the .wav format instead of the .mp3 format was the solution Pygame sound when started from terminal, not from Nodered
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | k1llerfr0g |
