我正在尝试创建一个程序,它将在语音命令上为我打开应用程序。这是我的代码
talking.py
import pyttsx
# INITIALISING THE SPEECH ENGINE
engine = pyttsx.init()
# GETTING A SPEECH RATE
rate = engine.getProperty('rate')
engine.setProperty('rate', rate-50)
# CHANGING VOICES
voices = engine.getProperty('voices')
for voice in voices:
engine.setProperty('voice',voice.id)
def saying(words):
engine.say(words)
engine.runAndWait()
Srecon.py
import speech_recognition as sr
from talking import saying
r = sr.Recognizer()
with sr.Microphone() as source:
saying("say something")
print("say something")
audio = r.listen(source)
def listen():
try:
saying("Sir, Did you just say " + r.recognize_google(audio))
print("did you just say " . r.recognize_google(audio))
except sr.UnknownValueError:
saying("I could not understand audio")
except sr.RequestError as e:
saying("google error; {0}".format(e))
当我运行Srecon.py时,我似乎得到的输出是
Say something
就是这样。我试过禁用我的防火墙和我的防病毒软件,我认为它们可能会导致一些问题,但即使在那之后我也会得到相同的响应。此外,我看到它正在使用谷歌识别语音是否有任何选项可以离线执行?