当有人说 Python 时如何开始录制?

我正在尝试制作一个使用语音识别的程序。现在我遇到了一个问题,即您必须按下按钮或 Enter 才能启动语音识别。有没有办法让你说出一个短语(有点像 Hey Google),它开始在 Python 3 中识别语音?

这是我的代码:


录制音频代码:

r = sr.Recognizer()


with sr.Microphone() as source:

    audio = r.listen(source)

x = r.recognize_google(audio)


print("I'm listening!")


try:

    print("You said: " + r.recognize_google(audio))

except speech_recognition.UnknownValueError:

    print("I am sorry but I couldn't understand you, try again.")

except speech_recognition.RequestError as e:

    print("Could not request results from Google Speech Recognition service; {0}".format(e))

提前致谢!


FFIVE
浏览 187回答 2
2回答

烙印99

代码:from pocketsphinx import LiveSpeechimport osfor i in LiveSpeech():    print(i)    if "hey Google" in str(i):       os.startfile("Your File.your_format")#works Perfectly and if you want to hide python console then save as youfile.pyw
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python