Python 在我转到另一个功能后,我的麦克风将恢复收听
每当我运行这段代码,并告诉启动函数“google”,它就会返回到另一个函数。我已经试着这样做了几天了,但仍然没有运气。任何帮助都将不胜感激:) 代码将返回到Python 在我转到另一个功能后,我的麦克风将恢复收听,python,Python,每当我运行这段代码,并告诉启动函数“google”,它就会返回到另一个函数。我已经试着这样做了几天了,但仍然没有运气。任何帮助都将不胜感激:) 代码将返回到的Listen(),源代码为sr.Mirophone 这就是我如何称呼google() 在调用Google函数中的listen方法时,需要指定一个函数参数phrase\u time\u limit。 短语\u time \u limit表示程序的等待时间,即等待用户输入的秒数。在这里,它将等待2秒钟。如果你不给任何时间限制,它将无限期地等待
的Listen(),源代码为sr.Mirophone
这就是我如何称呼google()
在调用
Google
函数中的listen
方法时,需要指定一个函数参数phrase\u time\u limit
。短语\u time \u limit
表示程序的等待时间,即等待用户输入的秒数。在这里,它将等待2秒钟。如果你不给任何时间限制,它将无限期地等待
从源代码文档:
phrase\u time\u limit
参数是最大秒数
这将允许一个短语在停止和
返回在指定时间限制之前已处理的短语部分
达到。产生的音频将是当时被切断的短语
限制。如果phrase\u timeout
为None
,则没有短语时间
限制
要澄清超时
参数
timeout
参数是此操作的最大秒数
在放弃并抛出一个短语之前,将等待一个短语开始
语音识别。WaitTimeoutError
异常。如果超时
为
无
,将不会有等待超时
有关更多详细信息,请查看
def Google():
打印(“您希望我为您搜索什么?”)
搜索引擎。说(“你想让我搜索什么?”)
engine.runAndWait()
使用sr.麦克风()作为源:
Search=r.listen(来源,短语_time_limit=2)#你的问题是什么?你如何调用Google()
函数?代码已经添加@SoumendraKumarSahooIt仍然返回listen(),令人遗憾
import webbrowser
import string
import time
import pyttsx3
import speech_recognition as sr
engine = pyttsx3.init()
r = sr.Recognizer()
def Listen():
with sr.Microphone() as sourceL:
print("Listening...")
Open = r.listen(sourceL, phrase_time_limit=2)
try:
if "Nova" in r.recognize_google(Open):
print("Nova Recieved...")
Command()
else:
Listen()
except:
Listen()
def Google():
print("what would you like me to search for you? ")
engine.say("what would you like me to search for you? ")
engine.runAndWait()
with sr.Microphone as source:
Search = r.listen(source)
Search = r.recognize(Search)
def Command():
print("You called me?")
engine.say("you called me? ")
engine.runAndWait()
Cr = sr.Recognizer()
with sr.Microphone() as source:
print("Listening For Command...")
CommandToDo = Cr.listen(source, phrase_time_limit=2)
print("...")
if "YouTube" in Cr.recognize_google(CommandToDo):
YouTube()
elif "Google" in Cr.recognize_google(CommandToDo):
Google()
else:
print("Command not recognized>> " + r.recognize_google(CommandToDo))
def Google():
print("what would you like me to search for you? ")
engine.say("what would you like me to search for you? ")
engine.runAndWait()
with sr.Microphone() as source:
Search = r.listen(source, phrase_time_limit=2) # <-- Here
Search = r.recognize_google(Search)
print(Search)