Trouble with Autorunning Python and Getting Sound to Play - Raspberry Pi Forums
i working stretch desktop version on 16gb sd card on pi 3.
project goal:
using 3.5mm audio jack connected pi 3 speaker , press button play specific .mp3.
used lxde terminal amixer cset numid3 = 2 // output analog instead of hdmi (i want know if there way change output hdmi analog via python)
after that, coded following
import rpi.gpio gpio
gpio.setmode(gpio.bcm)
import pygame
pygame import *
import time
try:
button = 23
gpio.setup(button, gpio.in, pull_up_down=gpio.pud_up)
while true:
if gpio.input(button) == false:
print("button pressed")
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load('lordoftherings.mp3')
pygame.mixer.music.play()
time.sleep(4)
finally:
gpio.cleanup()
print("gpio cleaned up")
program works me, when type command
sudo idle3 -i -r /home/pi/desktop/lotr.py //the name of program lotr , .mp3 file on desktop program
doesn't work. error
traceback (most recent call last):
file "/home/pi/desktop/pyprog/lotr.py", line 16, in <module>
pygame.mixer.music.load('lordoftherings.mp3')
pygame.error: couldn't open 'lordoftherings.mp3'
trying push button , play sound once turn on pi 3 without need of monitor or anything.
new ever playing or using microcontrollers , coding in python. please me find solution problem, going in circles.
project goal:
using 3.5mm audio jack connected pi 3 speaker , press button play specific .mp3.
used lxde terminal amixer cset numid3 = 2 // output analog instead of hdmi (i want know if there way change output hdmi analog via python)
after that, coded following
import rpi.gpio gpio
gpio.setmode(gpio.bcm)
import pygame
pygame import *
import time
try:
button = 23
gpio.setup(button, gpio.in, pull_up_down=gpio.pud_up)
while true:
if gpio.input(button) == false:
print("button pressed")
pygame.init()
pygame.mixer.init()
pygame.mixer.music.load('lordoftherings.mp3')
pygame.mixer.music.play()
time.sleep(4)
finally:
gpio.cleanup()
print("gpio cleaned up")
program works me, when type command
sudo idle3 -i -r /home/pi/desktop/lotr.py //the name of program lotr , .mp3 file on desktop program
doesn't work. error
traceback (most recent call last):
file "/home/pi/desktop/pyprog/lotr.py", line 16, in <module>
pygame.mixer.music.load('lordoftherings.mp3')
pygame.error: couldn't open 'lordoftherings.mp3'
trying push button , play sound once turn on pi 3 without need of monitor or anything.
new ever playing or using microcontrollers , coding in python. please me find solution problem, going in circles.
raspberrypi
Comments
Post a Comment