Dear Forum,
I'm a complete Python newbie and I'd like to try something for a project. The goal is to play an mp3 file that is on my computer when somebody hits a button that is connected to the arduino.
I manage to play a mp3 file from a small python program with this code:
from Tkinter import *
from tkSnack import *
root = Tkinter.Tk()
initializeSnack(root)
s = Sound()
def play():
s.play()
def load():
file = root.tk.call('eval', 'snack::getOpenFile')
s.read(file)
s.read('1.mp3')
s.play()
root.mainloop()
Now I want to implement this in a program that reads the serial port and when it reads the line "AUDIO", it plays this music file.
I tried this code: (based on something I found on the internet)
But it didn't work. I'm sure I made stupid mistakes. Could somebody be so kind to correct my mistakes?
import serial
from Tkinter import *
from tkSnack import *
def play():
s.play()
def load():
file = root.tk.call('eval', 'snack::getOpenFile')
s.read(file)
def capture():
print "Start capture"
ser = serial.Serial(4, 9600, timeout=0)
while (1):
line = ser.readline()
if (line == "AUDIO"):
s = Sound()
s.read('1.mp3')
s.play()
""" -------------------------------------------
MAIN APPLICATION
"""
root = Tkinter.Tk()
initializeSnack(root)
print "Start Application"
capture()
root.mainloop()
Thanks a lot! And pardon any stupid mistakes. i'm under time pressure and I don't have the time to learn Python right now...