Я пытаюсь создать приложение голосового помощника, используя tkinter в Python, и у меня две проблемы с моим кодом.
Фрагмент моего кода:
def listen_to_me():
msg2 = Message(root, text="Listening...", bg='yellow', font=('times', 14, 'italic'))
msg2.pack
msg2.place(x=200, y=220)
with sr.Microphone() as source:
audio = r.listen(source)
global query
query = r.recognize_google(audio, language='en-IN', show_all=True)
if query:
try:
(f"[Me]: {query}")
except:
engine.say("Sorry didn't quite catch that. Please repeat.")
return query
def reply():
while True:
global query
# Logic for executing tasks based on query
if 'wikipedia' in query:
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
query = query.replace("search", "")
query = query.replace("for", "")
results = wikipedia.summary(query, sentences=1)
speak(f'According to Wikipedia, {results}')
elif 'open youtube' in query:
speak('Opening Youtube')
webbrowser.open("https://youtube.com")
elif 'open stack overflow' in query:
speak('Opening StackOverflow')
webbrowser.open("https://stackoverflow.com")
elif 'what' in query and 'time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Sir, The time is {strTime}")
elif 'how are you' or 'what\'s up' in query:
speak('I am doing jolly good, sir.')
Проблема-1: Я получаю вывод, но кажется, что он застрял в al oop:
[MyAssistant]: Good evening! I am Jarvis. How may I help you today?
[MyAssistant]: I am doing jolly good, sir.
[MyAssistant]: I am doing jolly good, sir.
[MyAssistant]: I am doing jolly good, sir.
[MyAssistant]: I am doing jolly good, sir.
[MyAssistant]: I am doing jolly good, sir.
[MyAssistant]: I am doing jolly good, sir.
[MyAssistant]: I am doing jolly good, sir.
Проблема-2 : Я хочу преобразовать свой запрос в нижний регистр. Я пробовал следующее:
query = query.lower ()
Ошибка:
AttributeError: 'list' object has no attribute 'lower'
Заранее спасибо!