ImportError:无法导入名称“GenericAssistant”来自“神经意图”;
我正在尝试建立一个简单的语音助手。但是当我尝试运行时,我会遇到这样的错误。
> C:\Users\foobar>python
> C:\Users\foobar\Downloads\VoiceAssistance\VoiceAssistance\test.py
> Traceback (most recent call last): File
> "C:\Users\foobar\Downloads\VoiceAssistance\VoiceAssistance\test.py",
> line 1, in from neuralintents import GenericAssitant ImportError:
> cannot import name 'GenericAssitant' from 'neuralintents'
> (C:\Users\foobar\AppData\Local\Programs\Python\Python310\lib\site-packages\neuralintents_init_.py)
我也安装了这些东西;
pip install pyttsx3
pip install automatic-speech-recognition
pip install speech-recognition-python
pip install neuralintents
那就是我的源代码;
from neuralintents import GenericAssistant
import speech_recognition
import pyttsx3 as tts
import sys
recognizer = speech_recognition.Recognizer()
speaker = tts.init()
speaker.setProperty('rate',150)
todo_list = ['Go Shopping','Clean Room','Record Video']
def create_note():
global recognizer
speaker.say("What do you want to write onto your note boss?")
speaker.runAndWait()
done = False
while not done:
try:
with speech_recognition.Microphone() as mic:
recognizer.adjust_for_ambient_noise(mic,duration=0.2)
audio = recognizer.listen(mic)
note = recognizer.recognize_google(audio)
note = note.lower()
speaker.say("Choose a filename boss!")
speaker.runAndWait()
recognizer.adjust_for_ambient_noise(mic,duration=0.2)
audio = recognizer.listen(mic)
filename = recognizer.recognize_google(audio)
filename = filename.lower()
with open(f"{filename}.txt", 'w') as f:
f.write(note)
done = True
speaker.say(f"I successfully created the note {filename} boss")
speaker.runAndWait()
except speaker.recognition.UnknownValueError:
recognizer = speech_recognition.Recognizer()
speaker.say("I did not understand you! Please try again! boss")
speaker.runAndWait()
def add_todo():
global recognizer
speaker.say("What todo do you want to add boss?")
speaker.runAndWait()
done = False
while not done:
try:
with speech_recognition.Microphone() as mic:
recognizer.adjust_for_ambient_noise(mic,duration=0.2)
audio = recognizer.listen(mic)
item=recognizer.recognize_google(audio)
item=item.lower()
todo_list.append(item)
done=True
speaker.say(f"I added {item} to the to do list boss")
speaker.runAndWait()
except speech_recognition.UnknownValueError:
recognizer = speech_recognition.Recognizer()
speaker.say("I did not understand. Please try again boss!")
speaker.runAndWait()
def show_todos():
speaker.say("the items on your to do list are the following boss")
for item in todo_list:
speaker.say(item)
speaker.runAndWait()
def hello():
speaker.say("Hello.What can I do for you Boss?")
speaker.runAndWait()
def quit():
speaker.say("Okay Boss")
speaker.runAndWait()
sys.exit(0)
mappings = {
"greeting": hello,
"create_note": create_note,
"add_todo": add_todo,
"show_todos": show_todos,
"exit": quit
}
assistant = GenericAssistant('intents.json', intent_methods=mappings)
assistant.train_model()
while True:
try:
with speech_recognition.Microphone() as mic:
recognizer.adjust_for_ambient_noise(mic,duration=0.2)
audio = recognizer.listen(mic)
message=recognizer.recognize_google(audio)
message=message.lower()
assistant.request(message)
except speech_recognition.UnknownValueError:
recognizer=speech_recognition.Recognizer()
和意图文件;
{"intents":
[
{"tag": "greeting",
"patterns": ["Hey","Hello","What's up?","How is it going?","Hi"],
"responses": ["Hi Boss!"]},
{"tag": "create_note",
"patterns": ["Please create a new note","New note","Create a note","I want to create a note"],
"responses": [""]},
{"tag": "add_todo",
"patterns": ["I want to add a todo","add a new todo","add a todo to my list","new item on my todo list"],
"responses": [""]},
{"tag": "show_todos",
"patterns": ["Show my todos","What are my todos","What is on my todo list"],
"responses": [""]},
{"tag": "exit",
"pattern": ["Bye","Stop","Quit","I want to quit","Goodbye","I want to exit","I have to go"]},
]}
I'm trying to build a simple voice assistant.But i got a error like that when i try to run ;
> C:\Users\foobar>python
> C:\Users\foobar\Downloads\VoiceAssistance\VoiceAssistance\test.py
> Traceback (most recent call last): File
> "C:\Users\foobar\Downloads\VoiceAssistance\VoiceAssistance\test.py",
> line 1, in from neuralintents import GenericAssitant ImportError:
> cannot import name 'GenericAssitant' from 'neuralintents'
> (C:\Users\foobar\AppData\Local\Programs\Python\Python310\lib\site-packages\neuralintents_init_.py)
Also i installed those things;
pip install pyttsx3
pip install automatic-speech-recognition
pip install speech-recognition-python
pip install neuralintents
And thats my source code;
from neuralintents import GenericAssistant
import speech_recognition
import pyttsx3 as tts
import sys
recognizer = speech_recognition.Recognizer()
speaker = tts.init()
speaker.setProperty('rate',150)
todo_list = ['Go Shopping','Clean Room','Record Video']
def create_note():
global recognizer
speaker.say("What do you want to write onto your note boss?")
speaker.runAndWait()
done = False
while not done:
try:
with speech_recognition.Microphone() as mic:
recognizer.adjust_for_ambient_noise(mic,duration=0.2)
audio = recognizer.listen(mic)
note = recognizer.recognize_google(audio)
note = note.lower()
speaker.say("Choose a filename boss!")
speaker.runAndWait()
recognizer.adjust_for_ambient_noise(mic,duration=0.2)
audio = recognizer.listen(mic)
filename = recognizer.recognize_google(audio)
filename = filename.lower()
with open(f"{filename}.txt", 'w') as f:
f.write(note)
done = True
speaker.say(f"I successfully created the note {filename} boss")
speaker.runAndWait()
except speaker.recognition.UnknownValueError:
recognizer = speech_recognition.Recognizer()
speaker.say("I did not understand you! Please try again! boss")
speaker.runAndWait()
def add_todo():
global recognizer
speaker.say("What todo do you want to add boss?")
speaker.runAndWait()
done = False
while not done:
try:
with speech_recognition.Microphone() as mic:
recognizer.adjust_for_ambient_noise(mic,duration=0.2)
audio = recognizer.listen(mic)
item=recognizer.recognize_google(audio)
item=item.lower()
todo_list.append(item)
done=True
speaker.say(f"I added {item} to the to do list boss")
speaker.runAndWait()
except speech_recognition.UnknownValueError:
recognizer = speech_recognition.Recognizer()
speaker.say("I did not understand. Please try again boss!")
speaker.runAndWait()
def show_todos():
speaker.say("the items on your to do list are the following boss")
for item in todo_list:
speaker.say(item)
speaker.runAndWait()
def hello():
speaker.say("Hello.What can I do for you Boss?")
speaker.runAndWait()
def quit():
speaker.say("Okay Boss")
speaker.runAndWait()
sys.exit(0)
mappings = {
"greeting": hello,
"create_note": create_note,
"add_todo": add_todo,
"show_todos": show_todos,
"exit": quit
}
assistant = GenericAssistant('intents.json', intent_methods=mappings)
assistant.train_model()
while True:
try:
with speech_recognition.Microphone() as mic:
recognizer.adjust_for_ambient_noise(mic,duration=0.2)
audio = recognizer.listen(mic)
message=recognizer.recognize_google(audio)
message=message.lower()
assistant.request(message)
except speech_recognition.UnknownValueError:
recognizer=speech_recognition.Recognizer()
And intents file;
{"intents":
[
{"tag": "greeting",
"patterns": ["Hey","Hello","What's up?","How is it going?","Hi"],
"responses": ["Hi Boss!"]},
{"tag": "create_note",
"patterns": ["Please create a new note","New note","Create a note","I want to create a note"],
"responses": [""]},
{"tag": "add_todo",
"patterns": ["I want to add a todo","add a new todo","add a todo to my list","new item on my todo list"],
"responses": [""]},
{"tag": "show_todos",
"patterns": ["Show my todos","What are my todos","What is on my todo list"],
"responses": [""]},
{"tag": "exit",
"pattern": ["Bye","Stop","Quit","I want to quit","Goodbye","I want to exit","I have to go"]},
]}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你必须安装
i think you must install