Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
speaker = tts.Google()
# test internet connection
if not internet_on():
speaker.play_wav("./jarvis/wav/internet_err.wav")
return
try:
speaker.play_wav("./jarvis/wav/yes.wav")
audioInput = Microphone()
audioInput.listen()
# init new Voice class associated with audio
speech_to_text = stt.Google(audioInput)
# convert audio file into text and init a new Job class with text
recorded_text = speech_to_text.get_text()
job = Job(recorded_text)
# parse commands
first_word = (recorded_text.split(' ')[0]).lower()
second_word = ""
if recorded_text.find(' ') >= 1:
second_word = (recorded_text.split(' ')[1]).lower()
# initialize controller for web browser
controller = webbrowser.get()
# execute commands based on first word in query
def listen(self):
try:
audioInput = Microphone()
audioInput.listen()
speech_to_text = stt.Google(audioInput)
recorded_text = speech_to_text.get_text()
job = Job(recorded_text)
controller = webbrowser.get() # initialize controller for web browser
# parse first and second words in command
first_word = (recorded_text.split(' ')[0]).lower()
if recorded_text.find(' ') >= 1:
second_word = (recorded_text.split(' ')[1]).lower()
else:
second_word = ""
# execute commands based on first word in query
if first_word == "stop" or first_word == "no" \
or recorded_text.find('no stop') != -1:
print "---Accidental recording---"
def listen():
print "Initializing..."
speaker = tts.Google()
if not internet_on():
print("No Internet connection.")
speaker.play_wav("./hal-e/wav/internet_err.wav")
return
speaker.play_wav("./hal-e/wav/yes.wav")
try:
audioInput = Microphone()
audioInput.listen()
speech_to_text = stt.Google(audioInput)
recorded_text = speech_to_text.get_text()
job = Job(recorded_text)
# parse first and second words in command
first_word = (recorded_text.split(' ')[0]).lower()
if recorded_text.find(' ') >= 1:
second_word = (recorded_text.split(' ')[1]).lower()
else:
second_word = ""
# initialize controller for web browser
controller = webbrowser.get()
# execute commands based on first word in query
if first_word == "open":
def set_job(self):
"""
Send audio input to Google's Speech to text
engine to be interpreted, and then init a Job class
with the returned text if successful.
"""
speech_to_text = stt.Google(self.audioInput)
try:
recorded_text = speech_to_text.get_text().lower()
return Job(recorded_text)
except NotUnderstoodException:
print "Sorry, I didn't get that."
self.speaker.play_wav("./wav/didntget.wav")
return None
except ConnectionLostException:
print "No connection."
self.speaker.play_wav("./wav/internet_err.wav")
return None