import speech_recognition as sr
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 0.6
r.energy_threshold = 300
audio = r.listen(source, phrase_time_limit=5)
try:
print("Understanding...")
query = r.recognize_google(audio, language='en-in')
print(f'You said: {query}\n')
except Exception as e:
print("Say that again")
return "None"
return query
if __name__ == "__main__":
while True:
query = takeCommand()
if "wake up" in query:
from GreetMe import greetMe # ImportError occurs here
greetMe()
问候我.py
def greetMe():
print("Hello! How can I assist you?")
错误信息:
ImportError: cannot import name 'greetMe' from 'GreetMe'
确保两个文件位于同一目录中。 检查文件名和导入语句中的拼写错误。 已验证 GreetMe.py 包含greetMe 函数。
为什么我会收到此导入错误以及如何解决它?
您使用了 Python 包还是“普通”目录吗? 使用 python 目录可能会解决您的问题。