title: I am creating a virtual voice assistant, everything is fine but the time taken to execute the command is way too much. So can I reduce the time taken
body: <p>I took guidance from geeksforgeeks site. Everything seems fine but the time taken between the'Listening.....' and 'Recognising......' is way too much. So is there a way by which i can reduce theamount of time taken to execute the task. I have used the pyttsx3 module and Speech_recognition module.  Here's my code (please help I'm a bit new to python):</p>
  <pre><code>    engine = pyttsx3.init('sapi5')
      voices = engine.getProperty('voices')
      engine.setProperty('voice', voices[0].id)
  
      def speak(audio):
          engine.say(audio)
          engine.runAndWait()
      
      def wishMe():
          hour = int(datetime.datetime.now().hour)
          if hour&gt;= 0 and hour&lt;12:
              speak(&quot;Good Morning Mister Stark !&quot;)
      
          elif hour&gt;= 12 and hour&lt;17:
              speak(&quot;Good Afternoon Mister Stark !&quot;)  
      
          if hour &gt;17 and hour &lt;22:
              speak(&quot;Good Evening Mister Stark !&quot;)
  
          else:
              speak(&quot;You should be asleep Mister Stark, but&quot;)
  
          speak(&quot;How may i help you?&quot;)
  
  
      def takeCommand():
          
          r = sr.Recognizer()
          
          with sr.Microphone() as source:
              
              print(&quot;Listening...&quot;)
              r.pause_threshold = 1
              r.energy_threshold = 300
              audio = r.listen(source)
          
          try:
              print(&quot;Recognizing...&quot;)   
              query = r.recognize_google(audio, language ='en-in')
              print(f&quot;User said: {query}\n&quot;)
      
          except Exception as e:
              print(e)   
              print(&quot;Unable to Recognize your voice.&quot;) 
              return &quot;None&quot;
          
          return query
  
  
  
      if __name__ == '__main__':
      # clear = lambda: os.system('cls')
          
          # This Function will clean any
          # command before execution of this python file
          #clear()
          wishMe()
          
          while True:
              
              query = takeCommand().lower()
              
              # All the commands said by user will be
              # stored here in 'query' and will be
              # converted to lower case for easily
              # recognition of command
              if 'wikipedia' in query:
                  speak('Searching Wikipedia...')
                  query = query.replace(&quot;wikipedia&quot;, &quot;&quot;)
                  results = wikipedia.summary(query, sentences = 3)
                  speak(&quot;According to Wikipedia&quot;)
                  print(results)
                  speak(results)
                  continue 
      
              elif 'open youtube' in query:
                  speak(&quot;Here you go to Youtube\n&quot;)
                  webbrowser.open(&quot;www.youtube.com&quot;)
                  continue
      
              elif 'open google' in query:
                  speak(&quot;Here you go to Google\n&quot;)
                  webbrowser.open(&quot;www.google.com&quot;)
                  continue
  
              elif 'the time' in query:
                  strTime = datetime.datetime.now().strftime(&quot;% H:% M:% S&quot;)   
                  speak(f&quot;Sir, the time is {strTime}&quot;)
                  continue
  </code></pre>