I'm using Tkinter to design a basic front end for my app
global TextBoxText
TextBoxText = "Waiting for audio..."
I've created a global variable and set a default value to it above
def buttonClick():
r = sr.Recognizer()
global TextBoxText
with sr.Microphone() as source:
print("listening.....")
r.pause_threshold = 1
audio = r.listen(source)
TextBoxText = "Listening to audio..."
try:
print("Recognizing.....")
query = r.recognize_google(audio, language='en-in')
print(f"user said {query}\n")
TextBoxText = query
except Exception as e:
print("say that again please.....")
TextBoxText = "Could not catch that :(" + '\n' + "Press the button to speak again"
In this function, I'm updating TextBoxText
's value to different strings so that when the button is clicked, it can update the value accordingly.
ListenButton = Button(root, text="Start listening?", fg='white', bg = '#56717d', font= ('Helvetica', 11), command= buttonClick)
When ListenButton
is pressed, it will execute the code in the function and update the value of TextBoxText
too
TranslatedText = Text(root, height= 10, width= 40)
TranslatedText.insert('end', TextBoxText)
TranslatedText.config(state= 'disabled')
Unfortunately, I am not able to figure out how to display the updated text in TranslatedText
.
If you could help me out, I'd be really grateful