我无法在我的语音识别代码中生成 google/youtube 的研究结果
短信预约 -IT技能 免费直播动态提醒
问题内容
我正在尝试构建一个聊天机器人,它可以与人们互动并帮助他们快速更新。下面是我用来从 youtube/google 获取搜索结果的代码。请告诉我问题出在哪里?
maya_google_search.py代码:
import speech_recognition
import pyttsx3
import pywhatkit
from wikipedia import wikipedia
import wikipedia as googlescrap
import webbrowser
engine = pyttsx3.init("sapi5")
voices = engine.getproperty("voices")
engine.setproperty("voice", voices[1].id)
engine.setproperty("rate", 150)
def speak(audio):
engine.say(audio)
engine.runandwait()
def takecommand():
r = speech_recognition.recognizer()
with speech_recognition.microphone() as source:
print("listening.............")
r.pause_threshold = 1
r.energy_threshold = 300
audio = r.listen(source,0,4)
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")
speak("say that again")
return "none"
return query
query = takecommand().lower()
def googlesearch(query):
if "google" in query:
query = query.replace("maya", "")
query = query.replace("google search", "")
query = query.replace("google", "")
speak("this is what i found on google.....")
try:
pywhatkit.search(query)
result = googlescrap.summary(query,sentences=2)
speak("according to google..........")
speak(result)
except:
speak("no speakable output available")
def youtubesearch(query):
if "youtube" in query:
query = query.replace("maya", "")
query = query.replace("youtube search", "")
query = query.replace("youtube", "")
speak("this is what i found for your search!")
web = "https://www.youtube.com/results?search_query=" + query
webbrowser.open(web)
pywhatkit.playonyt(query)
speak("done, sir")
maya_ai.py代码:
import pyttsx3
import speech_recognition
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[1].id)
engine.setProperty("rate", 150)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def takeCommand():
r = speech_recognition.Recognizer()
with speech_recognition.Microphone() as source:
print("listening.............")
r.pause_threshold = 1
r.energy_threshold = 300
audio = r.listen(source,0,4)
try:
print("Understanding............")
query = r.recognize_google(audio, language='en-in')
print(f"You said: {query}\n")
# speak(query)
except Exception as e:
print("Say that again")
return "None"
return query
if __name__ == "__main__":
while True:
query = takeCommand().lower()
if "wake up" in query:
from maya_greeting import greetMe
greetMe()
while True:
query = takeCommand().lower()
if "go to sleep" in query:
speak("Ok sir, You can call me anytime...")
break
elif "hello" in query:
speak("Hello Sir, how are you?")
elif "i am fine" in query:
speak("That's really great to know sir....")
elif "how are you":
speak("i am perfectly alright sir.")
elif "thank you" in query:
speak("you're welcome sir")
elif "google" in query:
from maya_google_search import Googlesearch
Googlesearch(query)
elif "youtube" in query:
from maya_google_search import Youtubesearch
Youtubesearch(query)
elif "wikipedia" in query:
from maya_google_search import Wikisearch
Wikisearch(query)
如果我说 google sundar pichai,它只会打印我所说的内容,并说我很好,先生,或者什么也没有。
请帮我解决这个问题。
正确答案
改变
elif "how are you":
对于
elif "how are you" in query:
然后您需要添加最后的 else
语句,以防前面的条件都没有触发
以上就是我无法在我的语音识别代码中生成 google/youtube 的研究结果的详细内容,更多请关注编程网其它相关文章!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
我无法在我的语音识别代码中生成 google/youtube 的研究结果
下载Word文档到电脑,方便收藏和打印~
下载Word文档
猜你喜欢
我无法在我的语音识别代码中生成 google/youtube 的研究结果
问题内容我正在尝试构建一个聊天机器人,它可以与人们互动并帮助他们快速更新。下面是我用来从 youtube/google 获取搜索结果的代码。请告诉我问题出在哪里?maya_google_search.py代码:import s
2024-02-06