Skip to content

Commit

Permalink
flesh out error handling
Browse files Browse the repository at this point in the history
Don't absorb all exceptions silently.  Ctrl-C now works.

Adds uh-oh code path to differentiate actual errors from when it fails to
understand the statement (i.e. the sorry code-path).
  • Loading branch information
jvantuyl committed May 11, 2014
1 parent 063da8f commit e59faa1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions jarvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from src import microphone
from src import commonsense
from src import brain
from excp.exception import NotUnderstoodException

exit_flag = 0
tts_engine = google_tts.Google_TTS()
Expand Down Expand Up @@ -34,7 +35,7 @@ def sleep():
if 'wake' in words_stt_response or 'jarvis' in words_stt_response or 'wakeup' in words_stt_response:
tts_engine.say("Hello Sir, I am back once again.")
wakeup()
except:
except Exception:
pass


Expand All @@ -57,8 +58,12 @@ def wakeup():
response = k.respond(stt_response)
print(response)
tts_engine.say(response)
except:
except NotUnderstoodException:
commonsense.sorry()
except Exception:
print("Error in processing loop:")
traceback.print_exc()
commonsense.uhoh()

k.loadBrain('data/jarvis.brn')
try:
Expand Down
13 changes: 13 additions & 0 deletions src/commonsense.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
import random
speak_engine = google_tts.Google_TTS()

UHOH_PATH = "wav/uhoh/"
uhoh_files = os.listdir(UHOH_PATH)


def uhoh():
'''
This method will play pre-recorded uhoh wav files
'''
speak_engine.play_wav(
UHOH_PATH +
random.choice(uhoh_files)
)

SORRY_PATH = "wav/sorry/"
sorry_files = os.listdir(SORRY_PATH)

Expand Down
Binary file added wav/uhoh/sorry4.wav
Binary file not shown.

0 comments on commit e59faa1

Please sign in to comment.