I'm currently just testing an idea for something simple, using the idea of a workout program as an example. I'm very new to python and so this is more of a test than anything. What I want to have happen is open a window with the workout (just a tkinter label) but then passively in the background have a speech recognition command run to catch for the person saying "next". I'm not interested in having people tell me how to make other bits more effcient because I'm aware it's bad.
I'd just like a solution to make the command SpeechRecognition1
run passively whilst the "5 pressups"
label is displayed. Is there anyway to do this?
from tkinter import *
import sys
import speech_recognition as sr
def NextWorkout1():
workout1.destroy()
Workout2()
def Workout1():
global workout1
workout1 = Tk()
workout1.geometry("300x44")
workout1.configure(background="lightblue")
workout1.resizable(0,0)
workout1.title("Pressups")
insLabel = Label(workout1, text="5 pressups", fg="red", bg="lightblue", font="Arial 25 bold")
insLabel.pack()
workout1.mainloop()
def Workout2():
global workout2
workout2 = Tk()
workout2.geometry("300x50")
workout2.configure(background="lightblue")
workout2.resizable(0,0)
workout2.title("Starjumps")
insLabel = Label(workout2, text="15 starjumps", fg="red", bg="lightblue", font="Arial 25 bold")
insLabel.pack()
workout2.mainloop()
def SpeechRecognition1():
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
for i in range(1):
command = (r.recognize_google(audio))
if command == "next":
NextWorkout1()
else:
print("hi")
def SpeechRecognition2():
global WorkoutNumber
WorkoutNumber = 0
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
for i in range(1):
command = (r.recognize_google(audio))
if command == "next":
NextWorkout2()
else:
print("hi")
Workout1()