我正在尝试修复此命令以允许语音识别

问题描述

{' Computer Science ': 505,' Systems ': 977,' Maths ': 1064,' Electronics ': 1097}

但是我收到此错误返回

import speech_recognition as sr

r = sr.Recognizer()     # a recogniser to understand my voice 

with sr.Microphone() as source: # use the default microphone as the voice
        print('Listening....')
        voice = r.listen(source) # call speech recogniser to recognise the first phrase
try:        
    command = r.recognizer_google(voice) #  pass the audio to google
    print(command)
except:
    print('Could Not Understand Audio')

有人可以帮我解决这个问题吗?我已经从 3.8.2 降级到 python 3.8.1 但问题仍然存在

解决方法

您应该检查 speech_recognition 库的版本。您使用的版本似乎没有 recognizer_google 功能。

,

这是更新的代码:

import speech_recognition as sr

r = sr.Recognizer()     # a recogniser to understand my voice 

with sr.Microphone() as source: # use the default microphone as the voice
        print('Listening....')
        voice = r.listen(source) # call speech recogniser to recognise the first phrase
try:        
    command = r.recognize_google(voice) #  pass the audio to google
    print(command)
except:
    print('Could Not Understand Audio')

您在这里犯的错误:

  1. 没有任何名为 r.recognizer_google() 的成员,但在 r.recognize_google() 中有一个名为 Recognizer() 的成员
  2. 它如果你的Python的版本升级到最新,以及最好的speech_recognition模块,如果上面的代码不工作