我已经为语音识别机器人编写了一个演示项目。但我面临一些错误,表明该对象没有属性。我附上了下面的代码
def speak(audio):
print('Computer: ' + audio)
engine.say(audio)
engine.runAndWait()
我的命令的功能:
def myCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
query = r.recognize_google(audio, language='en-in')
print('User: ' + query + '\n')
except sr.UnknownValueError:
speak('Sorry sir! I didn\'t get that! Try typing the command!')
query = str(input('Command: '))
return query
主功能:
if __name__ == '__main__':
while True:
query = myCommand()
print(query)
query = query.lower()
print(query)
if 'open youtube' in query:
speak('okay')
webbrowser.open('www.youtube.com')
elif 'open google' in query:
speak('okay')
webbrowser.open('www.google.co.in')
else:
query = query
speak('Searching...')
try:
try:
res = client.query(query)
results = next(res.results).text
speak('WOLFRAM-ALPHA says - ')
speak('Got it.')
speak(results)
except:
results = wikipedia.summary(query, sentences=2)
speak('Got it.')
speak('WIKIPEDIA says - ')
speak(results)
except:
webbrowser.open('www.google.com')
speak('please give me Next Command! Sir!')
query = query.lower() AttributeError: 'NoneType' 对象没有属性 'lower'