def startDescription(): with sr.Microphone() as source: chime.success() audio = r.listen(source) try: chime.info() if "yes" in r.recognize_google(audio).__str__().lower(): print(r.recognize_google(audio).__str__().lower()) sayToSpeaker(audioResultInfo["DiseaseDescription"]) sayToSpeaker("Here are the Precautions ") for pre in audioResultInfo["Precautions"]: if pre != "": sayToSpeaker(pre) if askSession(): return True else: return False elif "no" in r.recognize_google(audio).__str__().lower(): if askSession(): return True else: return False else: sayToSpeaker( "Could not understand audio Say Yes if you want to listen Description and precautionary measurements?" ) startDescription() except: sayToSpeaker("Could not understand audio") startDescription()
def return_qr(self, url, token, camera_name): while 1: try: data = self.result_queue.get() # logger.info(f"Data: {data}") if self.check_data(data): # if check_data(data): chime.success(sync=True, raise_error=True) # barcodeData = data[0] # logger.info(f"Barcode: {barcodeData}") # # # Send result by API # code_data = list(barcodeData.split(",")) # headers = { # "token": self.token # } # data = { # "maphieu": str(code_data[1]), # "mahang": str(code_data[0]), # "soluong": str(code_data[2]), # "tencamera": self.camera_name # } # # res = requests.request("POST", self.url, headers=headers, data=data) # logger.info(res) else: pass except KeyboardInterrupt: logger.info("Kill all Processes Result Data") sys.exit(1)
def go_search(self): """ Search for relevant key in db """ phrase = self.search_field.text() if not phrase.strip(): chime.warning() return results = self.search_service.search(phrase=phrase) chime.success() self.build_table_rows(results)
def start(request): import pyaudio import speech_recognition as sr r = sr.Recognizer() import pyttsx3 eng = pyttsx3.init() eng.setProperty('rate', 135) voices = eng.getProperty('voices') eng.setProperty('voice', voices[0].id) def sayToSpeaker(text): eng.say(text) eng.runAndWait() sayToSpeaker( "Welcome. Say yes, if you want to start the audio system. Otherwise say no." ) answered = False #this is used to repeat untill user does not say yes or no while not answered: with sr.Microphone() as source: chime.success() audio = r.listen(source) try: chime.info() user_said = r.recognize_google(audio).__str__().lower() print(user_said) if "yes" in user_said: sayToSpeaker( "We are initiating the Audio System. Let's get started") answered = True return render(request, 'a_home.html') elif "no" in user_said: sayToSpeaker("We are getting you to the Visual Page") answered = True return render(request, 'symtomps.html') else: sayToSpeaker( "Please Please Say yes, if you want to start the audio system. Otherwise say no." ) except: sayToSpeaker("Could not understand audio. Please say again")
def beep(sound): #Arguments 0==4: 'ding' 1 : 'coin', 2 : 'robot_error', 3 : 'error', # 4 : 'ping', 5 : 'ready', 6 : 'success', 7 : 'wilhelm' if type(sound) == int: if sound > 7: if sound == 10: ch.theme('material') ch.info() else: ch.theme('chime') if sound == 9: ch.info() elif sound == 8: ch.success() else: bp.beep(sound) elif type(sound) == str: playsound("earcons/" + sound) time.sleep(.5)
def askSession(): sayToSpeaker( "Do You want to start another session? Say Yes if you want") with sr.Microphone() as source: chime.success() audio = r.listen(source) try: chime.info() if "yes" in r.recognize_google(audio).__str__().lower(): return True elif "no" in r.recognize_google(audio).__str__().lower(): return False else: sayToSpeaker( "Could not understand Say Yes if you want to start new session otherwise say no" ) askSession() except: sayToSpeaker("Could not understand audio") askSession()
def _save(self): crypt_password = run_encode(self.secret_key, self.password.text().encode("utf-8")) if not self.data: sql = "INSERT INTO passwords " \ "(parent, child, title, login, email, password, url, phone, created, modified) " \ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" self.cursor.execute( sql, (self.combo.currentText(), self.child.text(), self.title.text(), self.name.text(), self.email.text(), crypt_password, self.url.text(), self.phone.text(), self.created.text(), self.modified.text())) else: sql = "UPDATE passwords " \ "SET title=?, login=?, email=?, password=?, url=?, phone=?, modified=? " \ "WHERE id=?" self.cursor.execute( sql, (self.title.text(), self.name.text(), self.email.text(), crypt_password, self.url.text(), self.phone.text(), self.modified.text(), self.data[3])) self.connection.commit() self._close() chime.success()
def test_speed(): tic = time.time() chime.success() toc = time.time() assert toc - tic < .1
def test_no_exception(): chime.success(sync=True, raise_error=True)
def test_no_warning(): with pytest.warns(None) as record: chime.success(sync=True) assert len(record) == 0
def audioCalculate(request): inputList = [0 for x in range(0, 132)] sympDictionary = pd.read_csv( os.path.join(BASE_DIR, "static\DiseaseIndicator\symptomps.csv")).to_dict() symp = list(sympDictionary.keys()) import pyaudio import speech_recognition as sr r = sr.Recognizer() import pyttsx3 eng = pyttsx3.init() eng.setProperty('rate', 135) voices = eng.getProperty('voices') eng.setProperty('voice', voices[1].id) def sayToSpeaker(text): eng.say(text) eng.runAndWait() sayToSpeaker( "Answer me some questions in Yes or No. Say STOP to end this questionnaire" ) global AudioResSymp isStop = False for element in AudioResSymp: while True: sayToSpeaker("Are you Suffering from " + element + ".") with sr.Microphone() as source: chime.success() audio = r.listen(source) try: chime.info() print(r.recognize_google(audio).__str__().lower()) if "yes" in r.recognize_google(audio).__str__().lower(): print(element) for k in range(0, 131): if (element == symp[k]): inputList[k] = 1 break elif "stop" in r.recognize_google(audio).__str__().lower(): isStop = True break elif "no" in r.recognize_google(audio).__str__().lower(): isStop = False break else: sayToSpeaker("Could not understand audio Say Yes or no") except: sayToSpeaker("Could not understand audio") if isStop == True: break data = pd.read_csv( os.path.join(BASE_DIR, "static\DiseaseIndicator\dataSet.csv")) X = data.to_numpy() X = X[:, 0:132] Y = data.to_numpy() Y = Y[:, 132] X_Features_Train, X_Features_Test, y_Feature_Train, y_Feature_Test = train_test_split( X, Y, test_size=0.2, random_state=111) clf = K.KNN(5) clf.fit(X_Features_Test, X_Features_Train, y_Feature_Test, y_Feature_Train) inputList = np.array([inputList]) # X_test = np.array([[0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,0]]) clf.predict(inputList) disease = clf.prediction[0][0] Accuracy = clf.get_accuracy(inputList) import csv precautionDictionary = {} with open( os.path.join( BASE_DIR, "static\DiseaseIndicator\symptomPrecaution.csv")) as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') for row in csv_reader: prec = {row[0]: [row[1], row[2], row[3], row[4]]} precautionDictionary.update(prec) description_list = {} with open( os.path.join( BASE_DIR, "static\DiseaseIndicator\symptomDescription.csv")) as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') for row in csv_reader: description = {row[0]: row[1]} description_list.update(description) global audioResultInfo audioResultInfo = { 'DiseaseName': disease, 'Accuracy': Accuracy, 'DiseaseDescription': description_list[disease], 'Precautions': precautionDictionary[disease] } return render(request, 'audioResults.html', audioResultInfo)
'CAMERA_RTSP_URL', 'rtsp://*****:*****@192.168.23.103:554/Streaming/Channels/103') # rtsp_url = os.environ.get('CAMERA_RTSP_URL', 'rtsp://*****:*****@192.168.23.102:554/Streaming/Channels/101') camera_name = rtsp_url.split('@')[1] cam = camera(rtsp_url) logger.info(f"Camera is alive?: {cam.p.is_alive()}") prevTime = 0 while (1): # Video capture frame = cam.get_frame() data = decoder(frame) if data is not None: chime.success(sync=True, raise_error=True) ### FPS curTime = time.time() sec = curTime - prevTime fps = 1 / (sec) str = "FPS : %0.1f" % fps cv2.putText(frame, str, (0, 200), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 0)) prevTime = curTime cv2.imshow("Feed", frame) # # Check QR code in DB # if data is not None: # barcodeData = data[0]
f = open(filename, "r+") li = f.read() li = li.split('\n')[:-1] # print(li) li_set = set(li) announcements_set = set(announcements) if (len(li) == len(announcements)): if (li == announcements): print("info : there is no new post") logFile.write("info : there is no new post\n") else: print("info : there is a new post in announcements\a") logFile.write("info : there is a new post in announcements\n") for i in range(5): chime.success() # print("\a") time.sleep(1) new_posts = announcements_set.difference(li_set) new_posts = list(new_posts) print("\n======================") logFile.write("\n======================\n") print("These are new posts: ") for new_post in new_posts: print("=> " + new_post) logFile.write("=> " + new_post + "\n") print("======================\n") logFile.write("======================\n") writeToFile(filename, announcements) else: print("info : both have different lenghts")