def recognize_speech_from_mic_using_google(recognizer, microphone): print("\nSTATUS: LISTENING...") with microphone as source: # recognizer.adjust_for_ambient_noise(source) audio = recognizer.listen(source) # set up the response object response = {"success": True, "error": None, "transcription": None} GOOGLE_CLOUD_SPEECH_CREDENTIALS = get_google_creds(google_cred_file) LED_STATUS.recognizing() print("STATUS: RECOGNIZING...") try: response["transcription"] = recognizer.recognize_google_cloud( audio, credentials_json=GOOGLE_CLOUD_SPEECH_CREDENTIALS) except sr.UnknownValueError: # API was unreachable or unresponsive response["success"] = False response["error"] = "Unable to recognize speech" pass except sr.RequestError as e: # speech was unintelligible response["error"] = "API unavailable" pass return response
def get_heard_sentence(): listened_result = listener.listen() LED_STATUS.recognizing() if listened_result["success"] == True: sentence = str(listened_result["transcription"]) return sentence else: print(listened_result["error"]) return "None"
def find_names_utter_namank(): print("== starting the process == \n") time.sleep(2) sadhu.say("start") LED_STATUS.listening() time.sleep(0.5) # 1. --- > do speech recognition and SST < --- # listened_result = listener.listen() LED_STATUS.recognizing() if listened_result["success"] == True and listened_result["error"] == None: sentence = str(listened_result["transcription"]) print("STATUS: RECOGNIZED SST\n") print("SST: " + sentence + "\n") # 2. --- > Do name recognition within speech < --- # names = nr.get_names(sentence) if names == 'no valid names found': print("STATUS: No names found. Try Again!") LED_STATUS.no_names() sadhu.say("noNames") else: print("STATUS: FOUND NAMES\n") sadhu.say("found_names") LED_STATUS.found_names() # pretty print the names list for name in names: print(name) print("============\n") print("\nSTATUS: PREDICTIONS..") # 3. --- > Do destiny findings < --- # for name in names: print("\n" + name + "\n") # ring the bell (hit solenoid 15 for 0.1 sec) bell_module.ring(20, 0.2) # Chant before starting prediction sadhu.say("om") sadhu.say("name_header") sadhu.say_name(str(name)) SN = destiny.soul_number(name) destiny_number = SN SD = destiny.soul_desires(name) # IDN = destiny.inner_dream_number(name) # IDS = destiny.inner_dreams(name) print("\n") print("-----------------------------------------") print("Soul Urge Number / Heart Desire Number: " + str(SN)) print("-----------------------------------------") print(SD) print("\n") sadhu.say("desire_header") sadhu.say_number(str(SN)) time.sleep(1) sadhu.say('dt' + str(SN)) # time.sleep(1) # print("\n") # print("------------------------------------------------------") # print("Numerology Personality Number / Inner Dream Number " + str(IDN)) # print("------------------------------------------------------") # print(IDS) # print("\n") # sadhu.say("personality_header") # sadhu.say_number(str(IDN)) # time.sleep(1) # sadhu.say('su'+str(IDN)) # serial.pritn("name,6,jhsfgbhsbf,6, sdghvfsghdf;") print("\n*************** ^^^ **************") # ring the bell (hit solenoid 4 timesfor 0.25 sec) marking the ned of one prediction bell_module.ring(20, 0.2) LED_STATUS.deactivate() else: print(listened_result["success"]) print(listened_result["error"]) print("\n=> Start Again! hit the Bell <=\n") LED_STATUS.no_names() sadhu.say("noNames")
def find_names_utter_namank(): global destiny_number global found_name print(" => Starting the process") time.sleep(2) sadhu.say("start") LED_STATUS.listening() time.sleep(0.5) # 1. --- > do speech recognition and SST < --- # listened_result = listener.listen() LED_STATUS.recognizing() if listened_result["success"] == True and listened_result["error"] == None: sentence = str(listened_result["transcription"]) print("\n => STATUS: RECOGNIZED SST") print("\n => SST: " + sentence) # 2. --- > Do name recognition within speech < --- # names = nr.get_names(sentence) if names == 'no valid names found': print("\n => STATUS: No names found. Try Again!") print("\n => Start Again! hit the Bell") LED_STATUS.no_names() sadhu.say("noNames") destiny_number = None found_name = None else: print("\n => STATUS: FOUND NAMES:") sadhu.say("found_names") LED_STATUS.found_names() # pretty print the names list for name in names: # clean strings of any speacial character as we need one piece of string name = ''.join(e for e in name if e.isalnum()) name = name.lower() print(name) found_name = name print("\n => STATUS: PREDICTIONS:") # 3. --- > Do destiny findings < --- # for found_name in names: found_name = ''.join(e for e in name if e.isalnum()) found_name = found_name.lower() print("\n" + found_name + "\n") print("\n => Ringing auspicious bell") # ring the bell (hit solenoid 15 for 0.1 sec) bell_module.ring(10, 0.1) # Chant before starting prediction sadhu.say("om") sadhu.say("name_header") sadhu.say_name(str(found_name)) SN = destiny.soul_number(found_name) destiny_number = SN SD = destiny.soul_desires(found_name) print("\n") print("-----------------------------------------") print("Destiny Number and Heart Desire: " + str(SN)) print("-----------------------------------------") print(SD) print("\n") sadhu.say("desire_header") sadhu.say_number(str(SN)) time.sleep(1) sadhu.say('su' + str(SN)) # ring the bell (hit solenoid 4 timesfor 0.25 sec) marking # the end of one prediction print("\n => Ringing auspicious bell") bell_module.ring(10, 0.1) LED_STATUS.deactivate() else: print(listened_result["success"]) print(listened_result["error"]) print("\n => Start Again! hit the Bell") LED_STATUS.no_names() sadhu.say("noNames") destiny_number = None found_name = None