rahlstedt-audio/muttiOne.py
2021-05-01 11:18:03 +01:00

36 lines
903 B
Python

from time import sleep
import RPi.GPIO as GPIO
from soundplayer import SoundPlayer
import sys
from mfrc522 import SimpleMFRC522
reader = SimpleMFRC522()
p = SoundPlayer("/home/pi/Track03.wav", 1)
GPIO.setup(37, GPIO.IN)
#p.play(0.5)
status = 0
print("Hold a tag near the reader")
try:
while True:
if GPIO.input(37) == 1:
print("+")
sleep(0.1)
id, text = reader.read()
sleep(1)
print("ID: %s\nText: %s" % (id,text))
ss = text.strip()
i = int(ss)
if i != status or p.isPlaying()==False :
status = i
s = "/home/pi/Track0"+ss+".wav"
print(s)
p.stop()
sleep(2)
p = SoundPlayer(s,1)
p.play(0.5) # non-blocking, volume = 0.5
print ("isPlaying:", p.isPlaying(),s)
#sleep(5)
except KeyboardInterrupt:
GPIO.cleanup()