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.



raspberrypi



Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'