首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >kivy线程没有与我一起工作(应用程序没有响应)

kivy线程没有与我一起工作(应用程序没有响应)
EN

Stack Overflow用户
提问于 2022-01-26 18:05:32
回答 1查看 118关注 0票数 0

你好,伙计们,当我开始运行一些功能时,我的kivy应用程序有问题,程序停止响应,我试图使用线程来解决这个问题,但它不起作用。

这是小部件类:

代码语言:javascript
复制
class PyWidget(Widget):
  stop = threading.Event()

  def start_thread(self): 
    self.ids.mic.source = 'assets/open2.png'
    self.ids.mic.reload()
    time.sleep(1)
    threading.Thread(target=self.start_listening).start();

    
  @mainthread
  def start_listening(self):
    while True:
      try:
        time.sleep(1)
        print('Listening.......')
        voiceText = RecognizeVoice()
        # time.sleep(1)
        if 'hello' in voiceText and Talking(App, respone, RecognizeVoice):
          return
        
        # else: Talking(App, respone, RecognizeVoice)
        time.sleep(1)
      except Exception as e:
        print(f'start_listening: {e}')

RecognizeVoice函数启动麦克风并将用户声音发送到文本

代码语言:javascript
复制
def RecognizeVoice():
  try:
    with speechRec.Microphone() as sound:
      voice = recognizer.listen(sound)
      voiceText = recognizer.recognize_google(voice, language="en-US") #online 
      voiceText = voiceText.lower()
      print(f'Input : {voiceText}')
      return voiceText
  except speechRec.UnknownValueError as e:
    print(f'RecognizeVoice: {e}')
  except speechRec.RequestError as e:
    print(f'RecognizeVoice: {e}')
    respone('Sorry, something went wrong.')
代码语言:javascript
复制
# Text to speech
def respone(message):
  AI.say(message)
  AI.runAndWait()

在我的GUI中,我有一个按钮,当我单击start_thread函数启动时,所有其他函数都跟着它,我希望我解释了所有的事情。谢谢你的帮助

EN

回答 1

Stack Overflow用户

发布于 2022-01-26 19:57:58

@mainthread装饰器在start_listening()方法上击败threading。把那个装潢师移开。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70868220

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档