So basically I have this global variable called actual_translated_audio I need it to be global since I wanna use it in multiple functions. But it only works if you create a new function and then add a new button where the command is the name of the function. I need it to continuously access the global variable in the entire program if there are certain key words in said global variable it will return a new function which changes the text of a label I have to something in response to the text. I have tried literally everything. Please if someone can help that would be greatly appreciated.
global actual_translated_audio
actual_translated_audio = False
def open_file():
File_dialog = filedialog.askopenfilename(initialdir="/downlaods", title="Select a file")
#checking if something in file exists if so it will procced
if File_dialog:
try:
recongize = sr.Recognizer()
audio_file =sr.AudioFile(File_dialog)
with audio_file as source:
audio = recongize.record(source)
translated_audio = recongize.recognize_google(audio)
chat_label.config(text= "Neeko thinks you said: " +translated_audio)
chat_label.place(relx=0.1, rely=0.45, relwidth=0.8, relheight=0.85, anchor="w")
except ValueError:
print(" Only Compatabile files: PCM, WAV,AIFF/AIFF, Native FLACK ")
except AssertionError:
print("Please enter a file")
except:
print("Something else went wrong, make sure to send only allowed file types or send a different file")
if translated_audio:
global actual_translated_audio
actual_translated_audio = translated_audio
def idk():
global actual_translated_audio
if actual_translated_audio:
print(actual_translated_audio)
else:
idk()
give_up = Button(window, text ="I give up", command = idk).pack()
# upload file button
#chat_label = Label(chat_frame, text="translated_audio", bg="white", bd=10, wraplength=143, justify="left", anchor="nw")
#chat_label.place(relx=0.1, rely=0.45, relwidth=0.8, relheight=0.85, anchor="w")
Upload_file = Button(chat_frame, text="Upload File", command=open_file)
#Check_button = Button(chat_frame, text = "Yes", command = recongize_audio).pack()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…