我想为我的 JARVIS AI 制作一个热门词

如何解决我想为我的 JARVIS AI 制作一个热门词

我想问一下是否有办法为我在 python 3.7.6(windows 7) 中制作的 JARVIS AI 制作热门词。我希望每当我说“Hey Jarvis”时 JARVIS 都会被激活(就像 Hey siri)。下面给出了我的 jarvis 的代码。我已经尝试过名为 lshotword 的库,但它给出了一个名为 no module named tensorflow 的错误

import pyttsx3

import speech_recognition as sr
import datetime
import wikipedia
import time
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
import pyautogui
# Use female voice
import pyperclip
hiddenimports = [
   'pyttsx3.drivers','pyttsx3.drivers.dummy','pyttsx3.drivers.espeak','pyttsx3.drivers.nsss','pyttsx3.drivers.sapi5',]

engine = pyttsx3.init('sapi5')

voices = engine.getProperty('voice')
engine.setProperty('voice',voices)
engine.setProperty('rate',150)
engine.setProperty('volume',10)

def speak(audio):
 engine.say(audio)
 engine.runAndWait()

def wishMe():
   hour = int(datetime.datetime.now().hour)
   if hour>=0 and hour<12:
       speak("Good Morning!")
   elif hour>=12 and hour<18:
       speak("Good Afternoon!")
   else:
       speak("Good Evening!")
   speak("I am friday,is there anything to help you sir?")

def takecommand():
   r = sr.Recognizer()
   with sr.Microphone() as source:
       print("Listening....")
       r.pause_threshold = 1
       audio = r.listen(source)
   try:
    print("Recognizing....")
    query = r.recognize_google(audio,language='en-in')
    print(f"user said: {query}\n")
   except Exception as e:
     print(e)
     return "None"
   return query


def typenh():
   r = sr.Recognizer()
   with sr.Microphone() as source:
       print("Listening....")
       r.pause_threshold = 1
       audio = r.listen(source)
   try:
    print("Recognizing....")
    typethingh = r.recognize_google(audio,language='hi')
    print(f"user said: {typethingh}\n")
   except Exception as e:
     print(e)
     speak("sorry I could not understand,say that again please...")
     return "None"
   return typethingh



if __name__ == "__main__": 
   wishMe()
   while True:
    query = takecommand().lower()
    query.replace("could you","")
    query.replace("please","")
    if 'wikipedia' in query:
           speak('searching Wikipedia...')
           query = query.replace("wikipedia","")
           results = wikipedia.summary(query,sentences=2)
           speak("according to wikipedia")
           speak(results)
    if 'manav sampada' in query:
           speak('loging in to manav sampada')
           browser = webdriver.Chrome('D:\\chromedriver.exe')
           browser.get('http://ehrms.upsdc.gov.in/')
           elem = browser.find_element_by_partial_link_text('eHRMS Login')
           elem.get_attribute('href')
           time.sleep(1)
           elem.click()
           time.sleep(1)
           loginr = browser.find_element_by_xpath('//*[@id="txtusername"]')
           loginr.send_keys('your id ')
           time.sleep(1)
           select = Select(browser.find_element_by_id('ddldept'))
           select.select_by_visible_text('Basic Education')
           time.sleep(1)
           password = browser.find_element_by_xpath('//*[@id="txtpwd"]')
           password.send_keys('your password')
           speak('sir I have filled all userID password etc. but ')
           speak('sir you have to fill the human verification captha by yourself as I am just a bot ')
           speak('I hope I was able to assist you')
    if 'software' in query:
           speak('opening sir')
           query = query.replace("software","")
           pyautogui.click(27,880)
           pyautogui.typewrite(query)
           time.sleep(1)
           pyautogui.click(79,441)
    if 'send' and 'gmail' in query:
           speak('opening gmail')
           browser = webdriver.Chrome('D:\\chromedriver.exe')
           browser.get('https://accounts.google.com/b/0/AddMailService')
           time.sleep(1)
           login = browser.find_element_by_xpath('//*[@id="identifierId"]')
           login.send_keys('your gmail id @gmail.com')
           login.send_keys(Keys.ENTER)
           time.sleep(1)
           loginpwd = browser.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input')
           loginpwd.send_keys('your awesom password here')
           loginpwd.send_keys(Keys.ENTER)
           time.sleep(10)
           try:
               speak('just a sec')
               compose = browser.find_element_by_class_name('z0')
               time.sleep(2)
               compose.click()
               time.sleep(1)
               speak('whom do you want to send the gmail')
               sendto = takecommand().lower()
               sendto = ''.join(sendto.split())
               tom = browser.find_element_by_name('to')
               tom.send_keys(sendto)
               speak('what is the subject?')
               subject = browser.find_element_by_name('subjectbox')
               time.sleep(0.5)
               
               whatissu = takecommand()
               subject.send_keys(whatissu)
               body = browser.find_element_by_name('Message Body')
               speak('what is the main body?')
               mainbody = takecommand()
               body.send_keys(mainbody)

           except Exception as identifier:
               compose = browser.find_element_by_xpath('//*[@id=":jm"]/div/div')
               time.sleep(1)
               compose.click()
               time.sleep(1)
               speak('whom do you want to send the gmail')
               sendto = takecommand().lower()
               sendto = ''.join(sendto.split())
               tom = browser.find_element_by_name('to')
               tom.send_keys(sendto)                                                   
               subject = browser.find_element_by_name('subjectbox')
               time.sleep(0.5)
               speak('what is the subject?')
               whatissu = takecommand()
               subject.send_keys(whatissu)
               body = browser.find_element_by_name('Message Body')
               speak('what is the main body?')
               mainbody = takecommand()
               body.send_keys(mainbody)            
       
    if 'hindi' in query:
       speak('what to type?')
       typethingh = typenh()
       content = typethingh
       pyperclip.copy(content)
       time.sleep(0.5)
       pyautogui.hotkey('ctrl','v')

    if 'do you have a boyfriend' in query:
        speak('I am happy to be single')

    if 'siri' in query:
        speak('siri is smart but I dont like him')

    if 'how are you' in query:
        speak('I am good ')

    if 'i hate you' in query:
        speak('than go to siri or google. why are you even talking to me')

    if 'who is your creator' in query:
        speak("my creater is aditya maurya")

    if 'who made you' in query:
        speak('aditya maurya made me. he is also known as estriadi')

    if 'who created you' in query:
        speak('aditya maurya created me    ')

    if 'whatsapp' in query:
        browser = webdriver.Chrome('D:\\chromedriver.exe')
        speak('opening whatsapp web')
        browser.get('https://web.whatsapp.com/')
        speak('please scan the qr code. I am waiting for 10 seconds')
        time.sleep(10)
        try:
            find = browser.find_element_by_xpath('//*[@id="side"]/div[1]/div/label/div/div[2]')
            find.click()
            speak('tell the first word of the contact to whom you want to send the messege')
            sendmsg = takecommand()
            find.send_keys(sendmsg)
            time.sleep(1.5)
            find.send_keys(Keys.ENTER)
            try:
                typenum = browser.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
                typenum.click()
                speak('what do you want to send sir?')
                whattosend = takecommand()
                typenum.send_keys(whattosend)
                typenum.send_keys(Keys.ENTER)
            except Exception as identifier:
                speak('there is no contact as'+sendmsg)
        except Exception as identifier:
            speak('you did not make it in 10 seconds')


    if 'quit' in query:
       exit()

解决方法

基本上,您想在 Hey Jarvis 的开头就听到,如果您听到了,就会执行其余的代码。

我是这样做的:

import pyttsx3

import speech_recognition as sr
import datetime
import wikipedia
import time
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
import pyautogui
# Use female voice
import pyperclip
hiddenimports = [
   'pyttsx3.drivers','pyttsx3.drivers.dummy','pyttsx3.drivers.espeak','pyttsx3.drivers.nsss','pyttsx3.drivers.sapi5',]

engine = pyttsx3.init('sapi5')

voices = engine.getProperty('voice')
engine.setProperty('voice',voices)
engine.setProperty('rate',150)
engine.setProperty('volume',10)

def speak(audio):
 engine.say(audio)
 engine.runAndWait()

def wishMe():
   hour = int(datetime.datetime.now().hour)
   if hour>=0 and hour<12:
       speak("Good Morning!")
   elif hour>=12 and hour<18:
       speak("Good Afternoon!")
   else:
       speak("Good Evening!")
   speak("I am friday,is there anything to help you sir?")

def takecommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening....")
        r.pause_threshold = 1
        audio = r.listen(source)
    try:
        print("Recognizing....")
        query = r.recognize_google(audio,language='en-in')
        print(f"user said: {query}\n")
    except Exception as e:
        print(e)
        return "None"
    return query


def typenh():
   r = sr.Recognizer()
   with sr.Microphone() as source:
       print("Listening....")
       r.pause_threshold = 1
       audio = r.listen(source)
   try:
    print("Recognizing....")
    typethingh = r.recognize_google(audio,language='hi')
    print(f"user said: {typethingh}\n")
   except Exception as e:
     print(e)
     speak("sorry I could not understand,say that again please...")
     return "None"
   return typethingh

i = 0

#Edited From Here
n = 0
k = 0

print("Say Hey Jarvis To Begin Initiation Sequence") #Sounds SICK Right!
while (i<1):
    r = sr.Recognizer()
    with sr.Microphone() as source:
        audio = r.adjust_for_ambient_noise(source)
        n=(n+1)
        audio = r.listen(source)
        # interprete audio (Google Speech Recognition)
    try:
        s = (r.recognize_google(audio))
        message = (s.lower())

        if message == "hey jarvis":
            wishMe()
            k = 0
            while k == 0:
                query = takecommand().lower()
                query.replace("could you","")
                query.replace("please","")

                if 'sleep' in query:
                    speak("Entering Sleep Mode. Say Hey Jarvis To Wake Me Up!")
                    k = 1
                    print("Say Hey Jarvis To Begin Initiation Sequence")
                    #Editing Ends Here
                if 'wikipedia' in query:
                       speak('searching Wikipedia...')
                       query = query.replace("wikipedia","")
                       results = wikipedia.summary(query,sentences=2)
                       speak("according to wikipedia")
                       speak(results)
                if 'manav sampada' in query:
                       speak('loging in to manav sampada')
                       browser = webdriver.Chrome('D:\\chromedriver.exe')
                       browser.get('http://ehrms.upsdc.gov.in/')
                       elem = browser.find_element_by_partial_link_text('eHRMS Login')
                       elem.get_attribute('href')
                       time.sleep(1)
                       elem.click()
                       time.sleep(1)
                       loginr = browser.find_element_by_xpath('//*[@id="txtusername"]')
                       loginr.send_keys('your id ')
                       time.sleep(1)
                       select = Select(browser.find_element_by_id('ddldept'))
                       select.select_by_visible_text('Basic Education')
                       time.sleep(1)
                       password = browser.find_element_by_xpath('//*[@id="txtpwd"]')
                       password.send_keys('your password')
                       speak('sir I have filled all userID password etc. but ')
                       speak('sir you have to fill the human verification captha by yourself as I am just a bot ')
                       speak('I hope I was able to assist you')
                if 'software' in query:
                       speak('opening sir')
                       query = query.replace("software","")
                       pyautogui.click(27,880)
                       pyautogui.typewrite(query)
                       time.sleep(1)
                       pyautogui.click(79,441)
                if 'send' and 'gmail' in query:
                       speak('opening gmail')
                       browser = webdriver.Chrome('D:\\chromedriver.exe')
                       browser.get('https://accounts.google.com/b/0/AddMailService')
                       time.sleep(1)
                       login = browser.find_element_by_xpath('//*[@id="identifierId"]')
                       login.send_keys('your gmail id @gmail.com')
                       login.send_keys(Keys.ENTER)
                       time.sleep(1)
                       loginpwd = browser.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input')
                       loginpwd.send_keys('your awesom password here')
                       loginpwd.send_keys(Keys.ENTER)
                       time.sleep(10)
                       try:
                           speak('just a sec')
                           compose = browser.find_element_by_class_name('z0')
                           time.sleep(2)
                           compose.click()
                           time.sleep(1)
                           speak('whom do you want to send the gmail')
                           sendto = takecommand().lower()
                           sendto = ''.join(sendto.split())
                           tom = browser.find_element_by_name('to')
                           tom.send_keys(sendto)
                           speak('what is the subject?')
                           subject = browser.find_element_by_name('subjectbox')
                           time.sleep(0.5)
                           
                           whatissu = takecommand()
                           subject.send_keys(whatissu)
                           body = browser.find_element_by_name('Message Body')
                           speak('what is the main body?')
                           mainbody = takecommand()
                           body.send_keys(mainbody)

                       except Exception as identifier:
                           compose = browser.find_element_by_xpath('//*[@id=":jm"]/div/div')
                           time.sleep(1)
                           compose.click()
                           time.sleep(1)
                           speak('whom do you want to send the gmail')
                           sendto = takecommand().lower()
                           sendto = ''.join(sendto.split())
                           tom = browser.find_element_by_name('to')
                           tom.send_keys(sendto)                                                   
                           subject = browser.find_element_by_name('subjectbox')
                           time.sleep(0.5)
                           speak('what is the subject?')
                           whatissu = takecommand()
                           subject.send_keys(whatissu)
                           body = browser.find_element_by_name('Message Body')
                           speak('what is the main body?')
                           mainbody = takecommand()
                           body.send_keys(mainbody)            
                   
                if 'hindi' in query:
                   speak('what to type?')
                   typethingh = typenh()
                   content = typethingh
                   pyperclip.copy(content)
                   time.sleep(0.5)
                   pyautogui.hotkey('ctrl','v')

                if 'do you have a boyfriend' in query:
                    speak('I am happy to be single')

                if 'siri' in query:
                    speak('siri is smart but I dont like him')

                if 'how are you' in query:
                    speak('I am good ')

                if 'i hate you' in query:
                    speak('than go to siri or google. why are you even talking to me')

                if 'who is your creator' in query:
                    speak("my creater is John Cena(The OG Himself)")

                if 'who made you' in query:
                    speak('John Cena Made e. He Is An OG!')

                if 'who created you' in query:
                    speak('Booooob The BUILDER!!!')

                if 'whatsapp' in query:
                    browser = webdriver.Chrome('D:\\chromedriver.exe')
                    speak('opening whatsapp web')
                    browser.get('https://web.whatsapp.com/')
                    speak('please scan the qr code. I am waiting for 10 seconds')
                    time.sleep(10)
                    try:
                        find = browser.find_element_by_xpath('//*[@id="side"]/div[1]/div/label/div/div[2]')
                        find.click()
                        speak('tell the first word of the contact to whom you want to send the messege')
                        sendmsg = takecommand()
                        find.send_keys(sendmsg)
                        time.sleep(1.5)
                        find.send_keys(Keys.ENTER)
                        try:
                            typenum = browser.find_element_by_xpath('//*[@id="main"]/footer/div[1]/div[2]/div/div[2]')
                            typenum.click()
                            speak('what do you want to send sir?')
                            whattosend = takecommand()
                            typenum.send_keys(whattosend)
                            typenum.send_keys(Keys.ENTER)
                        except Exception as identifier:
                            speak('there is no contact as'+sendmsg)
                    except Exception as identifier:
                        speak('you did not make it in 10 seconds')


                if 'quit' in query:
                   exit()

    except Exception as e:
        pass

让我解释一下:

在第 76 行,我定义了另外两个我们稍后需要的变量:n 和 k。 在第 79 行,我打印了一条消息,告诉用户说“Hey Jarvis”以启动 AI。 在第 80 行,我开始了一个 while 循环。这个循环只监听 Hey Jarvis 和 Hey Jarvis!

while 循环与你的名为 takecommand() 的函数非常相似,所以我不会解释。

在第 91 行,它检查查询/消息是否等于 ONLY 'Hey Jarvis'。如果是,则它开始执行您的代码。

我所做的最后修改是让 AI 返回睡眠模式,然后再次等待用户说“Hey Jarvis”。

如果对 AI 说“sleep”,那么它会告诉用户它将进入睡眠模式。然后,它将 k 更改为等于 1。这会中断 while 循环,因为 while 循环的工作时间与 k == 0 一样长。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-