Python 中的语音识别错误(位置参数错误)
Speech recognition Error In Python (Positional Argument Error)
Python 当我 运行 这段代码时出现错误,我已经检查了它很多次。这里的来源是麦克风,但它一直在询问 'source' 的值。我应该怎么办。我应该将什么参数传递给 'source'?
密码是:
import pyttsx3
import datetime
import speech_recognition as sr
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishme():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning Sir")
elif hour>=12 and hour<18:
speak("Good afternoon Sir")
else:
speak("Good Evening")
speak("Hello Sir, I am Jarvis how can I help you?")
def takeCommand():
r = sr.Recognizer
with sr.Microphone() as source:
print("Listening....")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User Said: {query}\n" )
except Exception as e:
print("Say that again please...") #Say that again will be printed in case of improper voice
return "None"
return query
if __name__=="__main__" :
wishme()
takeCommand()
运行编译代码时出现的错误:
Traceback (most recent call last):
File "c:\Users\HPD Objects\Python\Jarvis\jarvis.py", line 54, in <module>
takeCommand()
File "c:\Users\HPD Objects\Python\Jarvis\jarvis.py", line 36, in takeCommand
audio = r.listen(source)
TypeError: listen() missing 1 required positional argument: 'source'
实际上是什么错误以及如何解决? (我是 python 的初学者,请放轻松)
而不是这个
r = sr.Recognizer
试试这个 r = sr.Recognizer()
Python 当我 运行 这段代码时出现错误,我已经检查了它很多次。这里的来源是麦克风,但它一直在询问 'source' 的值。我应该怎么办。我应该将什么参数传递给 'source'?
密码是:
import pyttsx3
import datetime
import speech_recognition as sr
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishme():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning Sir")
elif hour>=12 and hour<18:
speak("Good afternoon Sir")
else:
speak("Good Evening")
speak("Hello Sir, I am Jarvis how can I help you?")
def takeCommand():
r = sr.Recognizer
with sr.Microphone() as source:
print("Listening....")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("recognizing...")
query = r.recognize_google(audio, language='en-in')
print(f"User Said: {query}\n" )
except Exception as e:
print("Say that again please...") #Say that again will be printed in case of improper voice
return "None"
return query
if __name__=="__main__" :
wishme()
takeCommand()
运行编译代码时出现的错误:
Traceback (most recent call last):
File "c:\Users\HPD Objects\Python\Jarvis\jarvis.py", line 54, in <module>
takeCommand()
File "c:\Users\HPD Objects\Python\Jarvis\jarvis.py", line 36, in takeCommand
audio = r.listen(source)
TypeError: listen() missing 1 required positional argument: 'source'
实际上是什么错误以及如何解决? (我是 python 的初学者,请放轻松)
而不是这个
r = sr.Recognizer
试试这个 r = sr.Recognizer()