{"id":545,"date":"2023-05-01T20:16:31","date_gmt":"2023-05-01T20:16:31","guid":{"rendered":"https:\/\/rodamoya.com\/?p=545"},"modified":"2023-05-26T07:27:28","modified_gmt":"2023-05-26T07:27:28","slug":"mr-messeks-virtual-assistant","status":"publish","type":"post","link":"https:\/\/rodamoya.com\/index.php\/2023\/05\/01\/mr-messeks-virtual-assistant\/","title":{"rendered":"Mr.Messeks virtual assistant:"},"content":{"rendered":"\n<p class=\"has-text-align-center\">The Mr. Meeseeks project is a virtual assistant inspired by Rick and Morty. In the TV show, Mr. Meeseeks are created to fulfill an order, which in this case is similar. The Mr. Meeseeks Assist works with voice commands like Alexa and will fulfill many requests like playing music, security camera monitoring, chatbot functionality, automated reply messages on Whatsapp, and more.<\/p>\n\n\n\n<figure class=\"wp-block-video\"><video controls src=\"https:\/\/rodamoya.com\/wp-content\/uploads\/2023\/05\/FullSizeRender.mov\"><\/video><\/figure>\n\n\n\n<p class=\"has-text-align-center\"> This code uses the library speech recognition to detect the voice commands. Once the code is able to detect or interpret the speech and convert it to a string, it is necessary to define the words that will execute a command and then make them execute the pertinent function. There is an example of how Mr. Meeseeks is going to execute and play the function to play the song if he hears the word &#8220;play&#8221;.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>r = sr.Recognizer()\n    \n\n    with sr.Microphone() as source:\n\n        r.adjust_for_ambient_noise(source)\n        audio = r.listen(source)\n\n        try:\n            print(\"Has hablado:   \" + r.recognize_google(audio))\n            text_input = r.recognize_google(audio)\n\n            # Separar el input para detectar las palabras:\n            list_input = text_input.split(\" \")   \n            \n            # Si el input te play play the song\n            if \"play\" in list_input:   &lt;--- If play in the string sentence execute the function\n\n                # Nombre de la cancion lo que hay detras del play\n                nombre_cancion = text_input.split(\"play \")&#91;-1]\n\n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)\n\n                #Ejecutar la cancion:\n                seleciona_lacan\u00e7o(nombre_cancion)<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-center\">This project can be extended very easily by adding more functionalities and improving the management of the Hardware. However, this project is fun for Rick and Morty lovers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Code:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># Imports:\n\nfrom spotipy.oauth2 import SpotifyClientCredentials\nimport spotipy\nimport sys\nimport pprint\nimport webbrowser\nimport pyautogui\nfrom time import sleep\nimport speech_recognition as sr\nfrom gtts import gTTS\nimport os\nimport pandas as pd\nimport numpy as np\nimport seaborn as sns\nfrom datetime import datetime\nfrom math import *\nfrom datetime import datetime as date\nimport matplotlib.pyplot as plt\nfrom iteration_utilities import duplicates\nfrom iteration_utilities import unique_everseen\nimport time\n\n#Load Camera\nimport face_recognition\nimport cv2\nfrom simple_facerec import SimpleFacerec\n#from simple_facerec import SimpleFacerec\ncap = cv2.VideoCapture(0)\nimport openai as ai\nfrom selenium import webdriver\nimport random\nfrom selenium.webdriver.common.by import By\nimport pytesseract\nimport requests\n\nfrom email.message import EmailMessage\nimport ssl\nimport smtplib\nimport imghdr\nai.api_key = \"\"\nold_text = cv2.imread('Cropped Image.jpg')\n\n\n# Musica\n## Poner cancion:\n\n\ndef seleciona_lacan\u00e7o(can\u00e7o):\n    \n    #Credencials API y autentificar\n    client_id = \"\"\n    client_secret = \"\"\n    sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials(client_id, client_secret))\n\n    #Para de sonar la can\u00e7o anterior si es el cas\n    pyautogui.press('stop')\n\n    # Nombre de la can\u00e7o introduit\n    song = can\u00e7o.upper()\n    \n    #Buscar el autor\n    result = sp.search(song)\n    autor = result&#91;\"tracks\"]&#91;\"items\"]&#91;0]&#91;'artists']&#91;0]&#91;'name']\n    #bot_escuchandocancion(song, autor)\n    sleep(5)\n    print(\"You are lisening: \", song, \"--&gt;\", autor )  # &lt;------- Parlar \n    \n    #Ejecutar la cancion\n    name_song = result&#91;\"tracks\"]&#91;\"items\"]&#91;0]&#91;\"name\"].upper()\n    webbrowser.open(result&#91;\"tracks\"]&#91;\"items\"]&#91;0]&#91;\"uri\"])\n\n## Apagar la musica:\n\ndef stop_song():\n    \n    #Credencials API y autentificar\n    client_id = \"\"\n    client_secret = \"\"\n   sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials(client_id, client_secret))\n\n    #Para de sonar la can\u00e7o anterior si es el cas\n    pyautogui.press('stop')\n\n\n#Escoltar el que dice:\n\ndef estoy_escuchando_2(whats_app, conver):\n    r = sr.Recognizer()\n    \n\n    with sr.Microphone() as source:\n\n        r.adjust_for_ambient_noise(source)\n        print(\"Habla ahora:\")\n\n        audio = r.listen(source)\n\n        try:\n            print(\"Has hablado:   \" + r.recognize_google(audio))\n            text_input = r.recognize_google(audio)\n\n            #Detectar si es cancion:\n            # Separar el input para detectar las palabras:\n            list_input = text_input.split(\" \")   \n            \n            if \"Mr meeseeks\" in list_input:\n                print(\"hola\")\n                os.system(\"Aparcion_MR_Meeseks.mp3\")\n                \n            if \"meeseeks\" in list_input:\n                print(\"hola\")\n                os.system(\"Aparcion_MR_Meeseks.mp3\")  \n            \n            # Si el input te play play the song\n            if \"play\" in list_input:\n                nombre_cancion = text_input.split(\"play \")&#91;-1]\n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)\n                #Ejecutar la cancion:\n                seleciona_lacan\u00e7o(nombre_cancion)\n                \n            if \"Play\" in list_input:\n                nombre_cancion = text_input.split(\"play \")&#91;-1]\n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)\n                #Ejecutar la cancion:\n                seleciona_lacan\u00e7o(nombre_cancion)\n                \n            if \"security\" in list_input:  \n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)\n                print(\"Bien detectada security \")\n                camara_de_seguridad()\n                \n                \n            if \"stop\" in list_input and \"music\" in list_input:\n                stop_song()\n                seleciona_lacan\u00e7o(nombre_cancion)\n                stop_song()\n                os.system(\"Alldone.mp3\")\n                \n            if \"WhatsApp\" in list_input:\n                print(\"entra en whats app\")\n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)\n                #Ejecutar la WhatsApp\n                whats_app = True\n                \n            if \"what's\" in list_input and \"up\" in list_input:\n                print(\"entra en whats app\")\n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)\n                #Ejecutar la WhatsApp\n                whats_app = True\n                \n            if \"WhatsApp\" in list_input and \"stop\" in list_input:\n                print(\"Salir entra en whats app\")\n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)\n                #Ejecutar la WhatsApp\n                whats_app = False\n                \n                \n            if \"chat\" in list_input:\n                print(\"Aqui si chat\")\n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)\n                conver = True\nif \"news\" in list_input: \n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)\n                llegir_titulos()\n\n        except Exception as e:\n            text_input = \"\u00e7\u00e7\"\n    \n    print( \"Lo que he dicho:\" , text_input)\n    return text_input, whats_app, conver\n\n\n\nstop_song()\n\n\ndef estoy_escuchando():\n    r = sr.Recognizer()\n    \n\n    with sr.Microphone() as source:\n\n            r.adjust_for_ambient_noise(source)\n            print(\"Habla ahora:\")\n\n            audio = r.listen(source)\n\n        #try:\n            print(\"Has hablado:   \" + r.recognize_google(audio))\n            text_input = r.recognize_google(audio)\n\n            #Detectar si es cancion:\n            # Separar el input para detectar las palabras:\n            list_input = text_input.split(\" \")   \n            \n            if \"Mr meeseeks\" in list_input:\n                print(\"hola\")\n                os.system(\"Aparcion_MR_Meeseks.mp3\")\n                \n            if \"meeseeks\" in list_input:\n                print(\"hola\")\n                os.system(\"Aparcion_MR_Meeseks.mp3\")  \n            \n            # Si el input te play play the song\n            if \"play\" in list_input:\n                nombre_cancion = text_input.split(\"play \")&#91;-1]\n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)  \n                #Ejecutar la cancion:\n                seleciona_lacan\u00e7o(nombre_cancion)\n                \n            if \"Play\" in list_input:\n                nombre_cancion = text_input.split(\"play \")&#91;-1]\n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)  \n                #Ejecutar la cancion:\n                seleciona_lacan\u00e7o(nombre_cancion)\n                \n            if \"security\" in list_input:  \n                print(\"Bien detectada security \")\n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                #Mr Messeks voice\n                os.system(random_num)\n                #Ejecutar la camera:\n                camara_de_seguridad()\n                \n                \n            if \"stop\" in list_input and \"music\" in list_input:\n                stop_song()\n                os.system(\"Alldone.mp3\") \n                \n                \n            if \"WhatsApp\" in list_input:\n                print(\"entra en whats app\")\n                #Mr Messeks voice\n                random_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)\n                #Ejecutar la WhatsApp:\n                whats_app = True\n                \n            if \"what's\" in list_input and \"up\" in list_input:\n                print(\"entra en whats app\")\n                #Mr Messeks voice\nrandom_num = random.choice(lista_acceptar_tasca)\n                os.system(random_num)\n                #Ejecutar la WhatsApp:\n                whats_app = True\n                \n            if \"WhatsApp\" in list_input and \"stop\" in list_input:\n                #Mr Messeks voice\n                os.system(\"Alldone.mp3\") \n                print(\"Salir entra en whats app\")\n                whats_app = False\n                \n                \n            if \"chat\" in list_input:\n                print(\"Aqui si chat\")\n                conver = True\n                print(conver, \"AQUI QUE ? \")\n                \n\n                \n            \n                \n            \n            \n            \n\n\n        #except Exception as e:\n         #   print(\"Error \")\n    \n    #print( \"Lo que he dicho:\" , text_input)\n    return text_input, whats_app, conver\n\n\nlista_acceptar_tasca = &#91;\"CandoImmrmeseeks.mp3\", \"uuuhnice.mp3\", \"uuuhokey.mp3\", \"uuuhyeahcando.mp3\", \"Yes_sirr.mp3\"]\n\n\nrandom_num = random.choice(lista_acceptar_tasca)\nos.system(random_num)\n\n\n\n# # Sortida de string com audio \ndef bot_escuchandocancion(song, autor):\n\n    # The text that you want to convert to audio\n    mytext = ('You are lisening::' + song + 'of' + autor)\n\n    # Language in which you want to convert\n    language = 'en'\n\n    myobj = gTTS(text=mytext, lang=language, slow=False)\n\n    # Saving the converted audio in a mp3 file named\n    # welcome\n    myobj.save(\"welcome.mp3\")\n\n    # Playing the converted file\n    os.system(\"welcome.mp3\")\n\ndef bot_hablar(mytext):\n\n    # Language in which you want to convert\n    language = 'en'\n\n    myobj = gTTS(text=mytext, lang=language, slow=False)\n\n    # Saving the converted audio in a mp3 file named\n    # welcome\n    myobj.save(\"welcome.mp3\")\n\n    # Playing the converted file\n    os.system(\"welcome.mp3\")\n\n\n# # Chat Bot:\n# ## Meu\ndef most_frequent(List):\n    return max(set(List), key = List.count)\n\n\n# In&#91;17]:\n\n\ndef chat_bot_meu_prparar():\n    txtdata = pd.read_table(\"_chat_03_2023.txt\", on_bad_lines='skip') # --&gt; Enter the .txt flie here\n    # Column with all the information:\n    column_name = txtdata.columns&#91;0]\n    # Separate the information in different columns\n    txtdata&#91;\"Date\"] = txtdata&#91;column_name].str.split(\" \").str.get(0).str.title()\n    txtdata&#91;\"Hour\"] = txtdata&#91;column_name].str.split(\" \").str.get(1).str.title()\n    txtdata&#91;\"Name\"] = txtdata&#91;column_name].str.split(\" \").str.get(2).str.title()\n    txtdata&#91;\"Content\"] = txtdata&#91;column_name].str.split(\":\").str.get(3)\n    # columns to keep:\n    columns_save = &#91;'Date', 'Hour', 'Name', 'Content']\n    # New df:\n    df = txtdata&#91;columns_save]\n    # Delet \"&#91;\" brakets \"]\" and \":\" \n    df&#91;\"Date\"] = df&#91;\"Date\"].str.split(\"&#91;\").str.get(1)\n    df&#91;\"Hour\"] = df&#91;\"Hour\"].str.split(\"]\").str.get(0)\n    df&#91;\"Name\"] = df&#91;\"Name\"].str.split(\":\").str.get(0)\n    # Save the df without any nan values\n    df = df&#91;~df&#91;\"Date\"].isna()]\n    df = df&#91;df&#91;\"Content\"].str.contains(\"omitted\") == False]\n    # Crate a new column to merge the conversations:\n    df&#91;\"Change\"] = \"\" \n    df&#91;\"Count\"] = \"\"\n\n    # Max num of rows to do the while loop:\n    max_fun = df&#91;\"Name\"].count()\n    max_fun = max_fun - 2\n    # Create a loop that detects when it change writer, and count all the changes\n    # Get and Error but sill work\n    i = 0\n    coun = 0\n    while i &lt;= max_fun:\n        if (df&#91;\"Name\"].iloc&#91;i+1] == df&#91;\"Name\"].iloc&#91;i]):\n            i = i + 1\n            df&#91;\"Change\"].iloc&#91;i]= 1\n\n\n            df&#91;\"Count\"].iloc&#91;i ] = coun\n\n        else: \n            i = i + 1\n            df&#91;\"Change\"].iloc&#91;i] = 0\n\n            coun = coun + 1\n            df&#91;\"Count\"].iloc&#91;i] = coun\n    # Group the mensatgess of the same writer together until it change\n    df_gr = df.groupby(df&#91;\"Count\"]).first()\n    \n    return df_gr\n\n\n#df_gr = chat_bot_meu_prparar()\n\n\ndef chat_bot_meu(df_gr, msg):\n# read our mesatge and get all the words\n    #msg = input(\"Me:\")\n    list_msg =  msg.split(\" \")\n    \n    # Save the possible answers\n    Posiibles_respostes = &#91;]\n    \n    # Read all the mesatges to detect the once are similars are our msg\n    max_fun = df_gr&#91;\"Name\"].count()\n    max_fun = max_fun - 1\n    i = 0 \n    max_count = 0\n    while i &lt; max_fun:\n        \n        try:\n            #Get the content\n            content = df_gr&#91;\"Content\"].iloc&#91;i]\n\n            # Counter of similar words of our msg and the content\n            count_simitud= 0\n            \n            # Loop for all the words in our msg\n            for paraula in list_msg:\n                \n                # If the word in the msg is in the content add 1 in to the counter\n                if paraula in content:\n                    count_simitud = count_simitud +1\n\n            # If the number of similar word is the maximum delet all the oder saved answares\n\nif count_simitud &gt; max_count:\n                Posiibles_respostes = &#91;]\n\n            # If the number of similar word is the maximum or eaqual save the maximum, the position of the maximum, and all the possible answares:\n            if count_simitud &gt;= max_count:\n                \n                max_count = count_simitud\n                num_max = i\n\n                resposta_provisional = num_max + 1\n                \n                # List with the possible answars:\n                resposta = df_gr&#91;\"Content\"].iloc&#91;resposta_provisional]\n                Posiibles_respostes.append(resposta)\n        \n        except:\n            pass\n\n        # Add 2 because we want to read the content of the same person\n        i = i + 2\n    \n    # Get the most frequant answare:\n    resposta_def = most_frequent(Posiibles_respostes)\n    \n    resposta_def = resposta_def.replace(\"baby\", \"\")\n    \n\n    \n    # Print the answare of the Bot\n    print(\"Bot:\" , resposta_def)\n    print(\"\")\n\n\n\n## GPT\ndef chat(question,chat_log = None) -&gt; str:\n    \n    completion = ai.Completion()\n    \n    if(chat_log == None):\n        chat_log = start_chat_log\n    prompt = f\"{chat_log}Human: {question}\\nAI:\"\n    response = completion.create(prompt = prompt, engine =  \"davinci\", temperature = 0.85,top_p=1, frequency_penalty=0, \n    presence_penalty=0.7, best_of=10,max_tokens=150,stop = \"\\nHuman: \")\n    return response.choices&#91;0].text\n\ndef modify_start_message(chat_log,question,answer) -&gt; str:\n    if chat_log == None:\n        chat_log = start_chat_log\n    chat_log += f\"Human: {question}\\nAI: {answer}\\n\"\n    return chat_log\n\n\n# In&#91;23]:\n\n\ndef chat_bot_GPT( question):\n        ai.api_key = \"\"\n\n        completion = ai.Completion()\n\n        start_chat_log = \"\"\"Human: Hello, I am Human.\n        AI: Hello, human I am openai gpt3.\n        Human: How are you?\n        AI: I am fine, thanks for asking. \n        \"\"\"\n\n        resposta = chat(question,start_chat_log)\n        resposta = resposta.split(\"\\n\")&#91;0]\n        resposta = resposta.replace(\"openai gpt3\", \"Enric\")\n        print(\"AI: \",resposta)\n        return resposta\n\n\ndef Meeseeks_calling():\n    r = sr.Recognizer()\n\n    with sr.Microphone() as source:\n\n        r.adjust_for_ambient_noise(source)\n        print(\"Habla ahora:\")\n\n        audio = r.listen(source)\n\n        try:\n            print(\"Has hablado:   \" + r.recognize_google(audio))\n            text_input = r.recognize_google(audio)\n\n            #Detectar si es cancion:\n            # Separar el input para detectar las palabras:\n            list_input = text_input.split(\" \")   \n            \n            if \"Mr meeseeks\" in list_input:\n                os.system(\"Aparcion_MR_Meeseks.mp3\")\n                habaldo = True\n                \n            if \"meeseeks\" in list_input:\n                os.system(\"Aparcion_MR_Meeseks.mp3\") \n                habaldo = True\n                \n            if \"Mr\" in list_input and \"music\" in list_input:\n                os.system(\"Aparcion_MR_Meeseks.mp3\") \n                habaldo = True\n                \n            if \"mr.\" in list_input and \"music\" in list_input:\n                os.system(\"Aparcion_MR_Meeseks.mp3\") \n                habaldo = True \n                \n            \n            else:\n                habaldo = True\n                \n\n            \n            msg = estoy_escuchando()\n            list_msg =  msg.split(\" \")           \n              \n            \n            \n\n\n        except Exception as e:\n            print(\"Error \")\n            \n    return text_input, habaldo\n\n\n# # Facial recognition:\n\n# In&#91;26]:\n\n\nsfr = SimpleFacerec()\nsfr.load_encoding_images(r\"path images faces\")\n\ndef facial_recognition():\n    \n    name = \"\"\n    ret, frame = cap.read()\n    # Detect faces:\n    \n    face_locations, face_names = sfr.detect_known_faces(frame)\n    \n    for face_loc, name in zip(face_locations, face_names):\n        y1, x1, y2, x2 = face_loc&#91;0], face_loc&#91;1], face_loc&#91;2], face_loc&#91;3]\n        \n        cv2.putText(frame, name,(x1, y1 - 10), cv2.FONT_HERSHEY_DUPLEX, 1, (0, 0, 200), 2)\n        cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 200), 4)\n        \n    print(name)\n        \n    return name\n\ndef saludar(name, dic_today):\n    hora = datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\")\n    \n    # Limpiar dictionary si \u00e9s un dia nuevo:\n    try:\n        ultima_fecha = dic_today&#91;list(dic_today.keys())&#91;0]]\n        ultimo_dia = ultima_fecha&#91;8:10]\n\n        if hora&#91;8:10] != ultimo_dia:\n                dic_today = {}\n    except:\n        pass\n\n\n# Se ha visto hoy ? \n    personas_vistas_hoy = list(dic_today.keys())\n    if name in personas_vistas_hoy:\n        dic_today&#91;name] = hora\n        \n    else:\n        time.sleep(1.5)\n        saludo = \"Hi\" + name        \n        bot_hablar(saludo)\n        dic_today&#91;name] = hora\n        \n    return dic_today\n        \n    \n    \n\n\n# # Camara de seguridad:\n\nimport cv2\nimport mediapipe as mp\nimport time\nfrom datetime import datetime\nfrom math import *\nfrom datetime import datetime as date\n\ncap = cv2.VideoCapture(0)\n#Pose traking:\nmpDraw = mp.solutions.drawing_utils\nmpPose = mp.solutions.pose\npose = mpPose.Pose()\n\nfoto_enviada = False\ndef camara_de_seguridad():\n    foto_enviada = False\n    pTime = 0\n    last_seg = 61\n    i = 0\n\n    x_list = &#91;]\n    y_list = &#91;]\n    \n    parar_camara = True\n    while parar_camara == True:\n\n        # Conar segundos para mandar foto reportando movimiento:\n        hora = datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\")\n        decimal_segundo = hora&#91;-2]\n\n        success, img = cap.read()\n        imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)\n        results = pose.process(imgRGB)\n\n        if results.pose_landmarks:\n            mpDraw.draw_landmarks(img, results.pose_landmarks, mpPose.POSE_CONNECTIONS)\n            for id, lm in enumerate(results.pose_landmarks.landmark):\n                h, w, c = img.shape\n                #print(id, lm)\n                cx, cy = int(lm.x * w) ,int(lm.y * h)\n\n                if id == 12 or id == 11 or id == 23 or id == 24:\n\n                    #print(\"Hay un essser en esta camara\", decimal_segundo, foto_enviada)\n\n                    if (decimal_segundo in &#91;\"1\", \"3\", \"5\"]):\n                        foto_enviada = False\n\n                    if (decimal_segundo in &#91;\"0\", \"2\", \"4\"]) and foto_enviada == False:\n                        print(\"enviar foto\")\n                        foto_enviada = True\n                        bot_hablar(\"GET OUT OF MY ROOM!\")\n                        cv2.imwrite('intruso.jpg', img)\n                        send_intruso_email()\n\n        cv2.imshow(\"Video_pedo\", img)\n        \n        r = sr.Recognizer()\n\n        with sr.Microphone() as source:\n\n\nr.adjust_for_ambient_noise(source)\n            print(\"Habla ahora:\")\n\n            audio = r.listen(source)\n\n            try:\n                print(\"Has hablado:   \" + r.recognize_google(audio))\n                text_input = r.recognize_google(audio)\n                \n                #Detectar si es cancion:\n                # Separar el input para detectar las palabras:\n                list_input = text_input.split(\" \")   \n\n                if \"stop\" in list_input:\n                    os.system(\"Alldone.mp3\")\n                    print(\"Salir de la camara:\")\n                    parar_camara = False\n\n            \n            except:\n                pass\n\n\n        key = cv2.waitKey(1)    \n        if key == 27:\n            break\n\n    cap.release()\n    cv2.destroyAllWindows()\n\n\n# In&#91;33]:\n\n\n#camara_de_seguridad()\n## Email\ndef send_intruso_email():\n    \n    #Emisor\n    email_emisor = \"\"\n    contra_emisor = \"\"\n\n    #Receptor\n    email_receptor = \"\"\n    \n    #Mensaje:\n    asunto = \"Intruder!!\"\n    cuerpo = \"You have an intruder in your room!\"\n    \n    #__________________________________MENSAJE_____________________________\n    em = EmailMessage()\n    \n    # Emisor\n    em&#91;\"From\"] = email_emisor\n\n    #receeptor:\n    em&#91;\"To\"] = email_receptor\n\n    # Asunto\n    em&#91;\"Subject\"] = asunto\n    \n    #Definir correo\n    em.set_content(cuerpo)\n    contexto = ssl.create_default_context()\n    \n    # Abrir la foto:\n    with open('intruso.jpg', 'rb') as f:\n        file_data = f.read()\n        file_type = imghdr.what(f.name)\n        file_name = f.name\n\n    # A\u00f1adir la foto:\n    em.add_attachment(file_data, maintype='image', subtype=file_type, filename=file_name)\n\n    \n    with smtplib.SMTP_SSL(\"smtp.gmail.com\", 465, context = contexto) as smtp:\n        smtp.login(email_emisor, contra_emisor)\n        smtp.sendmail(email_emisor, email_receptor, em.as_string())\n\n\n# ## Tweepy:\nimport tweepy\nAPI_Key_Consumer = \"\"\nAPI_Key_Secret_Consumer = \"\"\nAccess_Token = \"\"\nAccess_Token_Secret = \"\"\n\nauth = tweepy.OAuthHandler(API_Key_Consumer, API_Key_Secret_Consumer )\nauth.set_access_token(Access_Token, Access_Token_Secret )\napi = tweepy.API(auth)\n\ndef send_intruso():\n    # upload media\n    media = api.media_upload(filename='intruso.jpg')# send with media\n    recipient_id = \"\"\n    api.send_direct_message(recipient_id=recipient_id, text='There is an intruder at home!', attachment_type='media', attachment_media_id=media.media_id)\n\n\n# # Whats app replay\nbrowser = webdriver.Chrome(executable_path = r\"path\\chromedriver.exe\")\nbrowser.get(\"https:\/\/web.whatsapp.com\/\")\n\n\ndef resposta_CHATGP3(question):\n        completion = ai.Completion()\n        start_chat_log = \"\"\"Human: Hello, I am Human. AI: Hello, human I am openai gpt3. Human: How are you? AI: I am fine, thanks for asking.  \"\"\"\n        \n        resposta = (chat(question,start_chat_log))\n        \n        try:\n            resposta = resposta.split(\"Human:\")&#91;0]\n        except:\n            pass\n        \n        return resposta\n\ndef chat(question,chat_log = None) -&gt; str:\n    completion = ai.Completion()\n    if(chat_log == None):\n        chat_log = start_chat_log\n    prompt = f\"{chat_log}Human: {question}\\nAI:\"\n    response = completion.create(prompt = prompt, engine =  \"davinci\", temperature = 0.85,top_p=1, frequency_penalty=0, \n    presence_penalty=0.7, best_of=10,max_tokens=150,stop = \"\\nHuman: \")\n    return response.choices&#91;0].text\n\ndef modify_start_message(chat_log,question,answer) -&gt; str:\n    if chat_log == None:\n        chat_log = start_chat_log\n    chat_log += f\"Human: {question}\\nAI: {answer}\\n\"\n    return chat_log\n\ndef responde_whats():\n    \n    # Ejecutar cada segundo\n    m = time.strftime(\"%S\")  \n    m = int(m)\n    res = m%2\n    \n    if res == 0:\n        \n        #________________Screemshot_____________________________________________________________\n        \n        browser.save_screenshot('Chat.png')\n        #browser.save_screenshot('Chat.png')\n        \n        # Guardar texto en   img\n        img = cv2.imread('Chat.png')\n        cv2.imshow(\"original\", img)\n\n        # Cropping an image\n                #eje y superior \/in eje x menor \/  major\n\n        cropped_image = img&#91;780:820, 650:1700 ]  # Depende de las mediadas de la pantalla\n\n        # Display cropped image\n        cv2.imshow(\"cropped\", cropped_image)\n        cv2.imwrite(\"Cropped Image.jpg\", cropped_image)\n        cv2.waitKey(27)\n        new_text = cv2.imread('Cropped Image.jpg')\n        old_text = cv2.imread('Cropped Image_old.jpg')\n        \n        difference = cv2.subtract(new_text, old_text)\n        b, g, r = cv2.split(difference)        \n        if cv2.countNonZero(b) == 0 and cv2.countNonZero(g) == 0 and cv2.countNonZero(r) == 0:\n            print(\"The images are completely Equal\")\n            time.sleep(10)\n            \n        \n        else:\n        \n            print(\"No son iguals\")\n            #_____________________________SCREMSHOT TO TXT____________________________________________\n            pytesseract.pytesseract.tesseract_cmd = r\"C:\\Program Files\\Tesseract-OCR\\tesseract\"        \n            texto = pytesseract.image_to_string(\"Cropped Image.jpg\")        \n            texto = texto.replace(\"\\n\", \" \")     \n\n            ##___RESPOSTA CHAT BOT_______________________________________________________________\n            #resposta = resposta_chatBot(texto)\n            resposta = resposta_CHATGP3(texto)\n            #_enviar resposta\n            elements = browser.find_element(By.XPATH, '\/\/*&#91;@id=\"main\"]\/footer\/div&#91;1]\/div\/span&#91;2]\/div\/div&#91;2]\/div&#91;1]\/div\/div&#91;1]')\n            elements.send_keys(resposta)\n            But_env = browser.find_element(By.XPATH, '\/\/*&#91;@id=\"main\"]\/footer\/div&#91;1]\/div\/span&#91;2]\/div\/div&#91;2]\/div&#91;2]\/button\/span')\n            But_env.click()\n\n            time.sleep(10)\n\n            browser.save_screenshot('Chat.png')\n\n            # Guardar texto en   img\n            img = cv2.imread('Chat.png')\n            cv2.imshow(\"original\", img)\n\n            # Cropping an image\n                    #eje y superior \/in eje x menor \/  major\n            cropped_image = img&#91;780:820, 650:1700 ] \n\n            # Display cropped image\n            cv2.imshow(\"cropped\", cropped_image)\n            cv2.imwrite(\"Cropped Image_old.jpg\", cropped_image)\n            cv2.waitKey(27)\n            \n\n\n            time.sleep(0.5)\n\n\n# # News\ndef llegir_titulos(): \n    \n    time.sleep(1)\n    \n    list_comp_country = &#91; \"SAP\", \"AAPL\", \"RIO\"]\n    \n    # READ THE NEWS:\n    news = requests.get(\"https:\/\/financialmodelingprep.com\/api\/v3\/stock_news?limit=50&amp;apikey=APIKEY\").json()    \n    \n    for company in list_comp_country:\n            try:\n                # Get the news of the companies:\n                news = requests.get(\"https:\/\/financialmodelingprep.com\/api\/v3\/stock_news?tickers=\"  + company + \"&amp;limit=1900000&amp;apikey=APIKEY\").json()  \n                # Titulo:\n                titulo = news&#91;1]&#91;\"title\"] \n                print(titulo)\n\n                titulo = \" news of:   \" + company + titulo\n                bot_hablar(titulo)\n                time.sleep(7)\n            except:\n                pass\n\n# # Main\n# person saw\ndic_today = {}\ndic_week = {}\n\nhabaldo = False\nwhats_app = False\nconver = False\nwhile True:\n    \n    \n\n#_______________________________________LISEN____________________________________________________    \n    #try:\n        # read our mesatge and get all the words\n    if habaldo != True:\n            text_input, habaldo = Meeseeks_calling()\n            #print(\"intro 1\")\n            habaldo = True\n            \n        \n    else:\n            #print( \"Otro\" )\n            #print(\"intro 2\")\n            habaldo = True\n            msg, whats_app, conver = estoy_escuchando_2(whats_app, conver)\n            #print( \"Lo que he dicho_ MIAN:\" , msg)\n            #list_msg =  msg.split(\" \")\n            #print(\"Otro\")\n            \n\n\n    \n    #except:\n        #sleep(1)\n        #pass\n    \n    \n#_______________________________________FACE RECOGNITION____________________________________________________    \n    try:\n        name = facial_recognition()\n\n        # Saludar si te ve por primera vez hoy\n        dic_today = saludar(name, dic_today)\n    except:\n        pass\n    \n    \n    \n    \n#_____________________________________Camara de Whats app:_____________________________________________________\n\n# Comando de voz\n# Ejeccucion:\n    #if whats_app == True:\n     #   responde_whats()\n    \n# Chat conver \n\n    print(\"conver\", conver, msg)\n\n    if conver == True:\n        print(\"Esta dentro chat\")\n        chat_bot_GPT(text_input)\n        chat_bot_meu(df_gr, text_input)\n        \n        \n\n#____________________________________________BREAK______________________________________________________________    \n    \n    \n    \n    \"\"\"if key == 27:\n        break\"\"\"\n\ncap.release()\ncv2.destroyAllWindows()\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Mr. Meeseeks project is a virtual assistant inspired by Rick and Morty. In the TV show, Mr. Meeseeks are created to fulfill an order, which in this case is similar. The Mr. Meeseeks Assist works with voice commands like Alexa and will fulfill many requests like playing music, security camera monitoring, chatbot functionality, automated &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/rodamoya.com\/index.php\/2023\/05\/01\/mr-messeks-virtual-assistant\/\" class=\"more-link\">Read more<span class=\"screen-reader-text\"> &#8220;Mr.Messeks virtual assistant:&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts\/545"}],"collection":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/comments?post=545"}],"version-history":[{"count":5,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts\/545\/revisions"}],"predecessor-version":[{"id":563,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/posts\/545\/revisions\/563"}],"wp:attachment":[{"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/media?parent=545"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/categories?post=545"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rodamoya.com\/index.php\/wp-json\/wp\/v2\/tags?post=545"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}