я перепробовал все функции, но ни одна из них не работает, я хочу, чтобы распознанная речь появлялась в Entrybox - PullRequest
0 голосов
/ 26 марта 2019

Как мне решить эту проблему? Я хочу, чтобы распознавание речи вводило текст в Entrybox, который я назвал entry_1, код работает правильно, когда я не использую графический интерфейс, но ничего не отображается после того, как я добавил tkinter.

from tkinter import *
import wikipedia
import wolframalpha
import speech_recognition as sr
import pyaudio
import pyspeech

class gui:
#gui
 def __init__(self):
        frame=Frame(root,width=600,height=0)
        frame.pack()
        self.label_1 = Label(root, text="Ask your Question:")
        self.entry_1 = Entry(root)
        self.entry_1.bind("<Return>",self.virtual)
        self.label_1.pack(side=LEFT,pady=20)
        self.entry_1.pack(side=LEFT,fill=X,pady=20,padx=10,expand=TRUE)
        self.entry_1.focus_set()

 def virtual(self,event):

  value = self.entry_1.get()
  value=value.lower()
  if value=='': #checking if input is null

   r = sr.Recognizer()
   with sr.Microphone() as source:
                  audio = r.listen(source)
   try:

        self.entry_1.insert(r.recognize_google(audio)) 
   except sr.UnknownValueError:
                   print("google speech could not understand audio")
   except sr.RequestError as e:
                   print("Could not request results from Google Speech Recognition service; {0}".format(e))
   else:
    try:
                   app_id = "some api" #enter you api
                   client = wolframalpha.Client(app_id)
                   res = client.query(value)
                   answers = next(res.results).text
                   print(answers)

    except:
                  print(wikipedia.summary(value,sentences=2))

root=Tk()
root.wm_title("Hi,i am Karen your personal assistant") #title for gui
b=gui()
root.mainloop()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...