python - gui tkinter python3 不工作总是停止
问题描述
我的tkinter gui代码是-
此代码显示我的 gui没有响应
我正在制作语音助手此代码我从另一个网站引用并尝试在我的 spyder 或 jupyter 中运行但无法运行它,因为它显示没有响应它根本没有将语音作为输入
我读了一些堆栈,但我不确定它是否有帮助,所以想要一些关于代码有什么问题的帮助
我读了一些帖子多线程会工作我应该试试吗?
from tkinter import*
import pyttsx3
import speech_recognition as sr
import pyaudio
import random
import time
from tkinter import messagebox
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
class Window(Frame):
#defining our main window
def __init__(self,master):
self.master=master
master.title("DREAM")
A=Label(master,text="try saying *what can you do*")
A.pack(side="top")
Button(master,text="listen",width=100,relief="groove",command=self.Processo_r).pack(side="bottom")
def Processo_r(self):
speech=str(self.speech_recog())
if speech=="What can you do":
self.functions()
def speak(self,output):
#initiating the speech engine
engine = pyttsx3.init()
#speaking the desired output
engine.say(output)
engine.runAndWait()
def functions(self):
self.speak("here is a list of what i can do")
messagebox.showinfo("DREAM functions", "1.Try saying 'Hi','Hello'" +
"\n2.Try asking 'What day is this?'" +
"\n3.Try asking 'What month is it?'" +
"\n4.Try asking 'What time is it?'" +
"\n5.You search in google by saying...'Search (or) Google <anything>'" +
"\n6.Play youtube by saying'YouTube... <video_name>'" +
"\n7.Search in Wikipedia by saying...'wikipedia...<anything>'" +
"\n8.To close say 'Bye' or 'Sleep' or 'See you later'")
def speech_recog(self):
#recognizer class
r=sr.Recognizer()
#Specifing the microphone to be activated
mic = sr.Microphone(device_index=1)
#listening to the user
with mic as s:
audio = r.listen(s, timeout=5)
r.adjust_for_ambient_noise(s)
#Converting the audio to text
try:
speech = r.recognize_google(audio)
return speech
except sr.UnknownValueError:
#calling the text to speech function
self.speak("please try again,couldnt identify")
except sr.WaitTimeoutError as e:
self.speak("please try again")
root=Tk()
#instance of the class
app=Window(root)
root.geometry("300x50")
#Runs the application until we close
root.mainloop()
解决方案
推荐阅读
- android - 带有飞溅的Android底部导航
- c# - 仅从 List 中获取最后一个值
- nlp - 如何为bert截断长文档?
- r - 从 Bookdown TOC 中省略索引页
- javascript - 根据 Gatsby 中的日期动态更改页面的 URL
- regex - REGEX - 正则表达式以空格开头或以空格结尾或以 > 开头并以 < 结尾并且有一个文本 'ghghfg'
- c# - 对来自多个来源(例如 Cognito 和 Azure)的令牌进行身份验证
- r - 在数据框中选择第一次出现的带有前缀的变量
- python - 如何在python中从数组和列表创建字典?
- git - git for Windows:提交时删除尾随空格