Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# generated speach file
speak.mp3


# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
Expand Down
9 changes: 3 additions & 6 deletions Stephanie/AudioManager/audio_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ def __init__(self, recognizer):
self.r = recognizer
self.c = config
self.speaker = Speaker()
self.start_text = self.c.config['LOGS']['start_text']
self.listened_success_text = self.c.config['LOGS']['listened_success_text']
self.listened_error_text = self.c.config['LOGS']['listened_error_text']
self.speech_directory = self.c.config['CORE']['speech_directory']
self.beep_start = self.get_speeches_folder(self.c.config['CORE']['beep_start'])
self.beep_end = self.get_speeches_folder(self.c.config['CORE']['beep_end'])
self.tts_option = self.c.config['TTS']['tts_player'].lower()

def get_audio_from_inbuilt(self, source, signals=True):
print(self.start_text)
print(_("command.ask"))
try:
if signals:
if self.tts_option == "os":
Expand All @@ -28,7 +25,7 @@ def get_audio_from_inbuilt(self, source, signals=True):
raise AssertionError("Fill in the tts_player option in config.ini file as either os or mixer.")
self.r.adjust_for_ambient_noise(source, duration=1)
audio = self.r.listen(source)
print(self.listened_success_text)
print(_("command.processing"))
if signals:
if self.tts_option == "os":
self.speaker.speak_from_os(self.beep_end)
Expand All @@ -39,7 +36,7 @@ def get_audio_from_inbuilt(self, source, signals=True):
return audio
except AssertionError as e:
print(e)
print(self.listened_error_text)
print(_("command.ask_repeat"))
return False

def listen(self, source, signals=True):
Expand Down
72 changes: 37 additions & 35 deletions Stephanie/AudioManager/audio_recognizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ def recognize_from_sphinx(self, audio):
# recognize speech using Sphinx
try:
text = self.r.recognize_sphinx(audio)
print("Sphinx thinks you said " + text)
print(_("audio.repeat_input").format("Sphinx", text))
return text
except self.UnknownValueError:
print("Sphinx could not understand audio")
print(_("error.audio.failed_understand").format("Sphinx"))
return False
except self.RequestError as e:
print("Sphinx error; {0}".format(e))
print(_("error.audio.failed_request_service").format("Sphinx", e))
return False

def recognize_from_google(self, audio):
Expand All @@ -28,114 +28,116 @@ def recognize_from_google(self, audio):
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
text = self.r.recognize_google(audio)
print("Google Speech Recognition thinks you said " + text)
print(_("audio.repeat_input").format("Google Speech Recognition", text))
return text
except KeyError:
print("Google Recognition couldn't understand your audio with enough confidence.")
print(_("error.audio.google_recognition.failed_understand"))
except self.UnknownValueError:
print("Google Speech Recognition could not understand audio")
print(_("error.audio.failed_understand").format("Google Speech Recognition"))
return False
except self.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
print(_("error.audio.failed_request_service").format("Google Speech Recognition", e))
return False

def recognize_from_google_cloud(self, audio):
# recognize speech using Google Cloud Speech
try:
google_cloud_speech_credentials = self.c.config['STT_KEYS']['google_cloud_speech_api']
except KeyError:
print("Api key not found in the config.ini file.")
print(_("error.missing_api_key"))
return False
try:
text = self.r.recognize_google_cloud(audio,
credentials_json=google_cloud_speech_credentials)
print("Google Cloud Speech thinks you said " + text)
print(_("audio.repeat_input").format("Google Cloud Speech", text))
return text
except self.UnknownValueError:
print("Google Cloud Speech could not understand audio")
print(_("error.audio.failed_understand").format("Google Cloud Speech"))
return False
except self.RequestError as e:
print("Could not request results from Google Cloud Speech service; {0}".format(e))
print(_("error.audio.failed_request_service").format("Google Cloud Speech", e))
return False

def recognize_from_wit(self, audio):
# recognize speech using Wit.ai
try:
wit_ai_key = self.c.config['STT_KEYS'][
'wit.ai_speech_api'] # Wit.ai keys are 32-character uppercase alphanumeric strings
# Wit.ai keys are 32-character uppercase alphanumeric strings
wit_ai_key = self.c.config['STT_KEYS']['wit.ai_speech_api']
except KeyError:
print("Api key not found in the config.ini file.")
print(_("error.missing_api_key"))
return False
try:
text = self.r.recognize_wit(audio, key=wit_ai_key)
print("Wit.ai thinks you said " + text)
print(_("audio.repeat_input").format("Wit.ai", text))
return text
except self.UnknownValueError:
print("Wit.ai could not understand audio")
print(_("error.audio.failed_understand").format("Wit.ai"))
return False
except self.RequestError as e:
print("Could not request results from Wit.ai service; {0}".format(e))
print(_("error.audio.failed_request_service").format("Wit.ai", e))
return False

def recognize_from_bing(self, audio):
# recognize speech using Microsoft Bing Voice Recognition
# Microsoft Bing Voice Recognition API keys 32-character lowercase hexadecimal strings
# Microsoft Bing Voice Recognition API keys 32-character
# lowercase hexadecimal strings
try:
bing_key = self.c.config['STT_KEYS']['bing_speech_api']
except KeyError:
print("Api key not found in the config.ini file.")
print(_("error.missing_api_key"))
return False
try:
text = self.r.recognize_bing(audio, key=bing_key)
print("Microsoft Bing Voice Recognition thinks you said " + text)
print(_("audio.repeat_input").format("Microsoft Bing Voice Recognition", text))
return text
except self.UnknownValueError:
print("Microsoft Bing Voice Recognition could not understand audio")
print(_("error.audio.failed_understand").format("Microsoft Bing Voice Recognition"))
return False
except self.RequestError as e:
print("Could not request results from Microsoft Bing Voice Recognition service; {0}".format(e))
print(_("error.audio.failed_request_service").format("Microsoft Bing Voice Recognition", e))
return False

def recognize_from_houndify(self, audio):
# recognize speech using Houndify
try:
houndify_client_id = self.c.config['STT_KEYS'][
'houndify_client_id'] # Houndify client IDs are Base64-encoded strings
houndify_client_key = self.c.config['STT_KEYS'][
'houndify_client_key'] # Houndify client keys are Base64-encoded strings
# Houndify client IDs are Base64-encoded strings
houndify_client_id = self.c.config['STT_KEYS']['houndify_client_id']
# Houndify client keys are Base64-encoded strings
houndify_client_key = self.c.config['STT_KEYS']['houndify_client_key']
except KeyError:
print("Api key not found in the config.ini file.")
print(_("error.missing_api_key"))
return False
try:
text = self.r.recognize_houndify(audio, client_id=houndify_client_id,
client_key=houndify_client_key)
print("Houndify thinks you said " + text)
print(_("audio.repeat_input").format("Houndify", text))
return text
except self.UnknownValueError:
print("Houndify could not understand audio")
print(_("error.audio.failed_understand").format("Houndify"))
return False
except self.RequestError as e:
print("Could not request results from Houndify service; {0}".format(e))
print(_("error.audio.failed_request_service").format("Houndify", e))
return False

def recognize_from_ibm(self, audio):
# recognize speech using IBM Speech to Text
try:
# IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
# IBM Speech to Text usernames are strings of the
# form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
ibm_username = self.c.config['STT_KEYS']['ibm_username']
# IBM Speech to Text passwords are mixed-case alphanumeric strings
ibm_password = self.c.config['STT_KEYS']['ibm_password']
except KeyError:
print("Api key not found in the config.ini file.")
print(_("error.missing_api_key"))
return False
try:
text = self.r.recognize_ibm(audio, username=ibm_username,
password=ibm_password)
print("IBM Speech to Text thinks you said " + text)
print(_("audio.repeat_input").format("IBM Speech to Text", text))
return text
except self.UnknownValueError:
print("IBM Speech to Text could not understand audio")
print(_("error.audio.failed_understand").format("IBM Speech to Text"))
return False
except self.RequestError as e:
print("Could not request results from IBM Speech to Text service; {0}".format(e))
print(_("error.audio.failed_request_service").format("IBM Speech to Text", e))
return False
4 changes: 2 additions & 2 deletions Stephanie/EventDispatcher/event_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ def close(self):

def sleep(self, sender):
self.sleep_status = True
print("The virtual assistant is going to sleep by %s method" % sender)
print(_("virtual_assistant.sleep").format(sender))
return self

def quit(self, sender):
self.active_status = True
print("The virtual assistant is being quit by %s method" % sender)
print(_("virtual_assistant.quit").format(sender))

def add(self, handle_name):
handle_event = getattr(self, handle_name)
Expand Down
14 changes: 7 additions & 7 deletions Stephanie/Modules/alpha_search_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ def do_a_search(self):
elif raw_text_array[i] == "search":
status = True
if status is False:
return "Can you possibly phrase it a bit better?"
return _("rephrase.ask")
phrase = phrase.strip()
try:
text = self.client.search(phrase)
except ConfidenceError:
return "Sorry, I couldn't find what you asked for, maybe try being a little more specific."
return _("error.search.no_results")
except InternalError:
return "It seems something is wrong with the wolframalpha search engine, maybe try asking later."
return _("error.search.wolframalpha")
except MissingTokenError:
return "Seems you haven't provided the API TOKEN for search engine, please add it in config file."
print("API TOKEN for wolframalpha search engine is missing, head in to docs to see how to properly fill the configurations for search engine.")
return _("error.search.no_api_token")
print(_("error.search.wolframalpha.no_api_token"))
except InvalidTokenError:
return "Seems you haven't provided the API TOKEN or it's wrong for search engine, please add it in config file."
print("API TOKEN for wolframalpha search engine is missing or is invalid, head in to docs to see how to properly fill the configurations for search engine.")
return _("error.search.incorrect_api_token")
print(_("error.search.wolframalpha.incorrect_api_token"))
return text
9 changes: 3 additions & 6 deletions Stephanie/Modules/base_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@ def get_configuration(self, key, section="MODULES"):
try:
value = self.config[section][key]
except KeyError:
print("API KEYS FOR '%s' is not provided in the config.ini file."
" Refer back to the docs, or just add the goddamn key." % key)
print(_("error.no_api_keys").format(key))
return False
if value:
return value
print("The correct API KEY wasn't provided or wasn't provided at all for %s, what the ... okay man"
" now look back at docs to find how to do that, is pretty simple just one line long. "
"Lazy ass" % key)
print(_("error.incorrect_api_keys").format(key))
return False

def write_configuration(self, key, value, section="MODULES"):
self.config.set(section, key, value)
with open(self.parent_configuration.abs_filename, 'w') as configfile:
self.config.write(configfile)
configfile.close()
return value
return value
9 changes: 3 additions & 6 deletions Stephanie/Modules/evernote_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@ def write_note(self):
try:
created_note = self.note_store.createNote(note) # Stores the new note in Evernote
except:
response = ("Note wasn't created successfully, you probably didn't spelled anything or spelled really "
"bad, Not my fault okay? It's never a program's fault.")
response = (_("error.note.create"))
print(response)
return response
if created_note:
return "I successfully wrote down your note."
return _("note.create.success")
else:
response = ("Note wasn't created successfully, you probably didn't spelled anything or spelled really "
"bad, Not my fault okay? It's never a program's fault. /s Refer back to docs.")
response = (_("error.note.create"))
print(response)
return response

30 changes: 11 additions & 19 deletions Stephanie/Modules/facebook_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ def get_birthday_reminders(self):
results = self.graph.request("me/friends",
args={'fields': 'id,name,birthday'})
except facebook.GraphAPIError:
response = ("I have not been authorized to query your Facebook. If you " +
"would like to check birthdays in the future, please visit " +
"the Jasper dashboard.")
response = (_("error.facebook.access.birthdays"))
return response
except:
return "I apologize, there's a problem with that service at the moment."
return _("error.service.unknown")

needle = datetime.datetime.now(tz=pytz.utc).strftime("%m/%d")

Expand All @@ -75,12 +73,11 @@ def get_birthday_reminders(self):

if len(people) > 0:
if len(people) == 1:
output = people[0] + " has a birthday today."
output = _("birthday.friend.today").format(people[0])
else:
output = "Your friends with birthdays today are " + \
", ".join(people[:-1]) + " and " + people[-1] + "."
output = _("birthday.friends.today") + ", ".join(people[:-1]) + _("join.and") + people[-1] + "."
else:
output = "None of your friends have birthdays today."
output = _("birthday.none.today")

return output

Expand All @@ -100,22 +97,19 @@ def get_notifications(self):
try:
results = self.graph.request("me/notifications")
except facebook.GraphAPIError:
response = ("I have not been authorized to query your Facebook. If you " +
"would like to check your notifications in the future, " +
"please visit the Stephanie facebook module configuraton.")
response = (_("error.facebook.access.notifications"))
return response
except:
return "I apologize, there's a problem with that service at the moment."
return _("error.service.unknown")
if not len(results['data']):
return "You have no Facebook notifications."
return _("facebook.notifications.none")

updates = []
for notification in results['data']:
updates.append(notification['title'])

count = len(results['data'])
response = ("You have " + str(count) +
" Facebook notifications. " + " ".join(updates) + ". ")
response = (_("facebook.notifications").format(str(count)) + " ".join(updates) + ". ")

return response

Expand All @@ -126,9 +120,7 @@ def status_update(self):
self.graph.put_wall_post(text)
self.assistant.say("You have successully put up a wall post.")
except facebook.GraphAPIError:
response = ("I have not been authorized to query your Facebook. If you " +
"would like to check your notifications in the future, " +
"please visit the Stephanie facebook module configuraton.")
response = (_("error.facebook.access.notifications"))
return response
except:
return "I apologize, there's a problem with that service at the moment."
return _("error.service.unknown")
Loading