speech_recognition | Speech recognition module for Python | Speech library

 by   Uberi Python Version: 3.9.0 License: BSD-3-Clause

kandi X-RAY | speech_recognition Summary

speech_recognition is a Python library typically used in Artificial Intelligence, Speech applications. speech_recognition has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub.
Speech recognition module for Python, supporting several engines and APIs, online and offline.
    Support
      Quality
        Security
          License
            Reuse
            Support
              Quality
                Security
                  License
                    Reuse

                      kandi-support Support

                        summary
                        speech_recognition has a medium active ecosystem.
                        summary
                        It has 6884 star(s) with 2219 fork(s). There are 283 watchers for this library.
                        summary
                        There were 1 major release(s) in the last 6 months.
                        summary
                        There are 250 open issues and 300 have been closed. On average issues are closed in 218 days. There are 29 open pull requests and 0 closed requests.
                        summary
                        It has a neutral sentiment in the developer community.
                        summary
                        The latest version of speech_recognition is 3.9.0
                        speech_recognition Support
                          Best in #Speech
                            Average in #Speech
                            speech_recognition Support
                              Best in #Speech
                                Average in #Speech

                                  kandi-Quality Quality

                                    summary
                                    speech_recognition has no bugs reported.
                                    speech_recognition Quality
                                      Best in #Speech
                                        Average in #Speech
                                        speech_recognition Quality
                                          Best in #Speech
                                            Average in #Speech

                                              kandi-Security Security

                                                summary
                                                speech_recognition has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
                                                speech_recognition Security
                                                  Best in #Speech
                                                    Average in #Speech
                                                    speech_recognition Security
                                                      Best in #Speech
                                                        Average in #Speech

                                                          kandi-License License

                                                            summary
                                                            speech_recognition is licensed under the BSD-3-Clause License. This license is Permissive.
                                                            summary
                                                            Permissive licenses have the least restrictions, and you can use them in most projects.
                                                            speech_recognition License
                                                              Best in #Speech
                                                                Average in #Speech
                                                                speech_recognition License
                                                                  Best in #Speech
                                                                    Average in #Speech

                                                                      kandi-Reuse Reuse

                                                                        summary
                                                                        speech_recognition releases are available to install and integrate.
                                                                        summary
                                                                        Build file is available. You can build the component from source.
                                                                        speech_recognition Reuse
                                                                          Best in #Speech
                                                                            Average in #Speech
                                                                            speech_recognition Reuse
                                                                              Best in #Speech
                                                                                Average in #Speech
                                                                                  Top functions reviewed by kandi - BETA
                                                                                  kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
                                                                                  Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
                                                                                  Get all kandi verified functions for this library.
                                                                                  Get all kandi verified functions for this library.

                                                                                  speech_recognition Key Features

                                                                                  Speech recognition module for Python, supporting several engines and APIs, online and offline.

                                                                                  speech_recognition Examples and Code Snippets

                                                                                  Speech_Recognition-PyTorch,資料預處理
                                                                                  Pythondot imgLines of Code : 67dot imgLicense : Permissive (MIT)
                                                                                  copy iconCopy
                                                                                  
                                                                                                                      class TextTransform: """Maps characters to integers and vice versa""" def __init__(self): char_map_str = """ ' 0  1 a 2 b 3 c 4 d 5 e 6 f 7 g 8 h 9 i 10 j 11 k 12 l 13 m 14 n 15 o 16 p 17 q 18 r 19 s 20 t 21 u 22 v 23 w 24 x 25 y 26 z 27 """ self.char_map = {} self.index_map = {} for line in char_map_str.strip().split('\n'): ch, index = line.split() self.char_map[ch] = int(index) self.index_map[int(index)] = ch self.index_map[1] = ' '
                                                                                  # 文字轉數字 def text_to_int(self, text): """ Use a character map and convert text to an integer sequence """ int_sequence = [] for c in text: if c == ' ': ch = self.char_map[''] else: ch = self.char_map[c] int_sequence.append(ch) return int_sequence # 數字轉文字 def int_to_text(self, labels): """ Use a character map and convert integer labels to an text sequence """ string = [] for i in labels: string.append(self.index_map[i]) return ''.join(string)
                                                                                  filelist = os.listdir(path) for filename in (filelist): file_path = os.path.join(path, filename) y, sr = librosa.load(file_path) duration = librosa.get_duration(y, sr) # 刪除長度超過30秒之音檔 if duration > 30: filepath = os.path.join(path, filename) os.remove(filepath)
                                                                                  Speech_Recognition-PyTorch,訓練設置
                                                                                  Pythondot imgLines of Code : 10dot imgLicense : Permissive (MIT)
                                                                                  copy iconCopy
                                                                                  
                                                                                                                      "n_cnn_layers": 3 "n_rnn_layers": 7 "rnn_dim": 1024 "n_class": 29 "n_feats": 128 "stride": 2 "dropout": 0.1
                                                                                  learning_rate = 5e-4 batch_size = 20 epochs = 100
                                                                                  Automatic speech recognition framework for python
                                                                                  Pythondot imgLines of Code : 26dot imgLicense : Strong Copyleft (CC BY-SA 4.0)
                                                                                  copy iconCopy
                                                                                  import speech_recognition as sr 
                                                                                  import pyttsx3  
                                                                                  r = sr.Recognizer()  
                                                                                  def SpeakText(command): 
                                                                                  
                                                                                      engine = pyttsx3.init() 
                                                                                      engine.say(command)  
                                                                                      engine.runAndWait() 
                                                                                  
                                                                                  while(1):     
                                                                                      try: 
                                                                                          with sr.Microphone() as source2: 
                                                                                              r.adjust_for_ambient_noise(source2, duration=0.2) 
                                                                                  
                                                                                              audio2 = r.listen(source2)  
                                                                                              MyText = r.recognize_google(audio2) 
                                                                                              MyText = MyText.lower() 
                                                                                              print("Did you say "+MyText) 
                                                                                              SpeakText(MyText) 
                                                                                  
                                                                                      except sr.RequestError as e: 
                                                                                          print("Could not request results; {0}".format(e)) 
                                                                                  
                                                                                      except sr.UnknownValueError: 
                                                                                          print("unknown error occured") 
                                                                                  
                                                                                  Community Discussions

                                                                                  Trending Discussions on speech_recognition

                                                                                  Speech Recognition(IBM) username and password
                                                                                  chevron right
                                                                                  Google speech recognition not recognizing certain words / phrases like um and er | python
                                                                                  chevron right
                                                                                  Find A value in list , if there are multiple value print all the values else print the corresponding values from another list
                                                                                  chevron right
                                                                                  Wikipedia Library shows error if input not given exactly to the name of a page of wikipedia
                                                                                  chevron right
                                                                                  Error when creating jarvis ai, object is not callable, etc
                                                                                  chevron right
                                                                                  Build a voice assistant to open the application with a path in the curly bracket
                                                                                  chevron right
                                                                                  How to open wa.me link directly on Whastapp desktop application, rather than it redirecting to web (on PC)?
                                                                                  chevron right
                                                                                  IndexError: tuple index out of range when I try to create an executable from a python script using auto-py-to-exe
                                                                                  chevron right
                                                                                  No Audio with pyttsx3 Library in Python 3 (No errors)
                                                                                  chevron right
                                                                                  How to close all the processes one by one in a program that operates with multiprocessing by means of an 'if' validation found in one of them process?
                                                                                  chevron right

                                                                                  QUESTION

                                                                                  Speech Recognition(IBM) username and password
                                                                                  Asked 2022-Apr-11 at 08:50

                                                                                  I hope to use IBM speech recognition service without - curl or ibm_watson module.
                                                                                  And my attempt is below:

                                                                                  import speech_recognition as sr
                                                                                  r = sr.Recognizer()
                                                                                  text = r.recognize_ibm(audio,username='',password='')
                                                                                  

                                                                                  Even though, I have 'Service credentials' for IBM cloud - speech to text, I cannot find correct form for the function.
                                                                                  In the documents of recognize_ibm(), it is said that I need to enter the link_1 to find my username in XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX format.
                                                                                  But the link_1 is broken. Where can I find the username and password?

                                                                                  I also tried text = r.recognize_ibm(audio,username='apikey',password=api_key) as the previous answers link_2.

                                                                                  ANSWER

                                                                                  Answered 2022-Apr-11 at 08:50

                                                                                  Here are the official API docs for Speech to Text: https://cloud.ibm.com/apidocs/speech-to-text

                                                                                  It includes various samples and further links. You can use the IAMAuthenticator to turn an API key into an authentication token and to handle refresh tokens. If you don't want to make use of the SDK you have to deal with the IBM Cloud IAM Identity Service API on your own. The API has functions to obtain authentication / access tokens.

                                                                                  I often use a function like this to turn an API key into an access token:

                                                                                  def getAuthTokens(api_key):
                                                                                      url     = "https://iam.cloud.ibm.com/identity/token"
                                                                                      headers = { "Content-Type" : "application/x-www-form-urlencoded" }
                                                                                      data    = "apikey=" + api_key + "&grant_type=urn:ibm:params:oauth:grant-type:apikey"
                                                                                      response  = requests.post( url, headers=headers, data=data )
                                                                                      return response.json()
                                                                                  

                                                                                  You could

                                                                                  Source https://stackoverflow.com/questions/71821208

                                                                                  QUESTION

                                                                                  Google speech recognition not recognizing certain words / phrases like um and er | python
                                                                                  Asked 2022-Apr-01 at 02:56

                                                                                  So it seems google speech recognition is taking out certain parts of my speech like um, er and ahh. The problem is I want these to be recognized, I can not seem to figure out how to enable this.

                                                                                  Here is the code:

                                                                                  import pyttsx3
                                                                                  
                                                                                  recognizer = speech_recognition.Recognizer()
                                                                                  
                                                                                  vocal_imperfections = 0
                                                                                  
                                                                                  vi_list = ['hmm', 'umm', 'aha', 'ahh', 'uh', 'um', 'er']
                                                                                  
                                                                                  while True:
                                                                                      try:
                                                                                          with speech_recognition.Microphone() as mic:
                                                                                              recognizer.adjust_for_ambient_noise(mic, duration=0.2)
                                                                                              audio = recognizer.listen(mic)
                                                                                              text = recognizer.recognize_google(audio, language='en-IN', show_all=True)
                                                                                              #text = recognizer.recognize_ibm(audio)
                                                                                              if text != []:
                                                                                                  text = text['alternative'][0]['transcript']
                                                                                                  if any(word in text for word in vi_list):
                                                                                                      vocal_imperfections = vocal_imperfections+1
                                                                                                  print(text)
                                                                                                  print(vocal_imperfections)
                                                                                  
                                                                                  
                                                                                      except speech_recognition.UnknownValueError():
                                                                                          recognizer = speech_recognition.Recognizer()
                                                                                          continue
                                                                                  

                                                                                  It works as wanted just google takes out the vocal imperfections. Does anyone know how to enable this, or alternative free real time speech recognition that will recognize vocal imperfections?

                                                                                  Example: If I were to say: "um, I think today is the 30th" Google would return: "I think today is the 30th"

                                                                                  ANSWER

                                                                                  Answered 2022-Apr-01 at 02:56

                                                                                  I took a look at the Google Cloud Speech-to-text API docs and didn't see anything relevant (as of March 2022). I also came across these related resources:

                                                                                  All evidence suggests that it isn't possible to use the Google Cloud Speech-to-text service (at this time), and that you'll have to seek alternative services. I won't rehash the alternatives listed in the resources, but several are provided and you'll have to pick which one best suits your particular needs.

                                                                                  Also, you may already know this (so apologies if you do), but these types of words are typically called "filler" and/or "hesitation" words. That might be helpful to you while researching the topic.

                                                                                  The good news is that the SpeechRecognition module (I think that's what you're using based on your code) supports several different engines, so hopefully one of those provides filler words.

                                                                                  Source https://stackoverflow.com/questions/71682150

                                                                                  QUESTION

                                                                                  Find A value in list , if there are multiple value print all the values else print the corresponding values from another list
                                                                                  Asked 2022-Mar-18 at 12:09

                                                                                  I have two lists :

                                                                                  Keyword = ['Dog', 'Cat', 'White Cat', 'Lion', 'Black Cat']
                                                                                  Definition = ['Mans Best Friend', 'The cat is a domestic species of a small carnivorous mammal', 'White  cats are cute', 'Lions are Carnivores Wild Animal', 'Black Cats are Black in color']
                                                                                  

                                                                                  I am getting a voice input in 'query' from the following command:

                                                                                  import speech_recognition as sr
                                                                                  
                                                                                  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)   
                                                                                          print("Unable to Recognize your voice.") 
                                                                                          return "None"
                                                                                       
                                                                                      return query
                                                                                  
                                                                                  query = takeCommand().Capitalize()
                                                                                  

                                                                                  Now if the query contains Dog in it I want to print the corresponding definition from the list i.e. 'Man's Best Friend', If the query contains Cat , I want to show the user that there are multiple Keywords that have 'Cat' in them i.e. 'Cat', 'White Cat', 'Black Cat' and if the word inside query isn't in the list I want to print "No keywords Found, Please check your Keyword"

                                                                                  Does anyone has an idea on how to solve this?

                                                                                  Input output for different cases:

                                                                                  Input: query has 'Dog' in it. The program should check for if there are more than 1 word that has Dog in it. If Yes it should print all the keywords that has Dog in it, if No then it should print the corresponding definition . In this case of Keywords the output for Dog should be the corresponding definition i.e. 'Mans Best Friend'.

                                                                                  Input: Query has 'Cat' in it. In this case of keywords there are 3 keywords that have cat in them i.e. 'Cat' , 'Black Cat', 'White Cat' So here the code should Print these Keywords instead of their definition. So output of this case : We have found multiple keywords : 'Cat' , 'Black Cat', 'White Cat'

                                                                                  Input : Query has 'Panther' in it. There is no Panther in Keywords So it should print "There are no Matching Keywords".

                                                                                  ANSWER

                                                                                  Answered 2022-Mar-18 at 12:09
                                                                                  Keyword = ['Dog', 'Cat', 'White Cat', 'Lion', 'Black Cat']
                                                                                  Definition = ['Mans Best Friend', 'The cat is a domestic species of a small carnivorous mammal', 'White  cats are cute', 'Lions are Carnivores Wild Animal', 'Black Cats are Black in color']
                                                                                  
                                                                                  def take_cmd(cmd):
                                                                                      multiple_val=[]
                                                                                      if cmd in Keyword:
                                                                                          for i,j in enumerate(Keyword):
                                                                                              if cmd in j:
                                                                                                  multiple_val.append((i,j))
                                                                                          if len(multiple_val)>1:
                                                                                              i_removed=[j for i in multiple_val for j in i if type(j)!=int]
                                                                                              print(f"We have found multiple keywords : {i_removed}")
                                                                                          else:
                                                                                              print(Definition[Keyword.index(cmd)])
                                                                                      else:
                                                                                          print("There are no Matching Keywords")
                                                                                  

                                                                                  What this code does is:

                                                                                  1. Checks if the value inputed exists in the Keyword or not, if not then would return "There are no Matching Keywords".
                                                                                  2. If the value exists, then would check if there are multiple instances or the value is available in multiple indexes or not.
                                                                                  3. If that returns true as well then it appends it to multiple_vals. If length of multiple_val if greater than 1 then only it would show f"We have found multiple keywords : {i_removed}".
                                                                                  4. otherwise shows the corresponding index in Definition.

                                                                                  Source https://stackoverflow.com/questions/71522230

                                                                                  QUESTION

                                                                                  Wikipedia Library shows error if input not given exactly to the name of a page of wikipedia
                                                                                  Asked 2022-Mar-12 at 13:51

                                                                                  If I give a voice command using speech recognition module to search something in Wikipedia if I don't say exactly it shows an error. For example: I say(National Defence Academy) no Wikipedia page is named so but(National Defence Academy (India)) is a page, so it shows results. I want to search for the nearest page as per my voice command. Here is my code:

                                                                                  import pyttsx3
                                                                                  import datetime
                                                                                  import speech_recognition as sr
                                                                                  import Wikipedia
                                                                                  import web-browser
                                                                                  import os
                                                                                  engine = pyttsx3.init('sapi5')
                                                                                  
                                                                                  voices = engine.getProperty('voices')
                                                                                  
                                                                                  engine.setProperty('voice', voices[1].id)
                                                                                  def speak(audio):
                                                                                      engine.say(audio)
                                                                                      engine.runAndWait()
                                                                                  def voiceinput():
                                                                                      r=sr.Recognizer()
                                                                                      with sr.Microphone() as source:
                                                                                          print("I am listening")
                                                                                          r.pause_threshold=1
                                                                                          audio=r.listen(source)
                                                                                  try:
                                                                                          print("Recognizing...")
                                                                                          speak("Recognizing...")
                                                                                          query=r.recognize_google(audio, language="en-in")
                                                                                          print(f"You mean {query}\n")
                                                                                          speak(f"You mean {query}\n")
                                                                                  except Exception as e:
                                                                                          print("Please repeat")
                                                                                          speak("please repeat?")
                                                                                          return "None"
                                                                                  return query
                                                                                  if "search" in query:
                                                                                      speak("Searching Wikipedia")
                                                                                      query=query.replace("search", "")
                                                                                      results=wikipedia.summary(query, sentences=2)
                                                                                      print("According to Wikipedia")
                                                                                      print(results)
                                                                                      speak("According to Wikipedia")
                                                                                      speak(results)
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2022-Mar-12 at 13:51

                                                                                  A similar search has to be made in this case. You are using the Wikipedia package and not Pywikibot as tagged above. Anyway here is a code snippet how a similar search can be done with Pywikibot:

                                                                                    >>> from difflib import get_close_matches
                                                                                    >>> import pywikibot
                                                                                    >>> site = pywikibot.Site('wikipedia:en')  # create a Site object
                                                                                    >>> title = 'National Defence Academy'
                                                                                    >>> gen = site.search('intitle:' + title, total=10, namespaces=0)
                                                                                    >>> titles = [page.title() for page in gen]  # list of strings required
                                                                                    >>> result = get_close_matches('National Defence Academy', titles)
                                                                                    >>> found = pywikibot.Page(site, result[0])
                                                                                  

                                                                                  found is a Page object with closest match of the given title. Get its text:

                                                                                    >>> found.text[:100]
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/71369216

                                                                                  QUESTION

                                                                                  Error when creating jarvis ai, object is not callable, etc
                                                                                  Asked 2022-Mar-10 at 05:33

                                                                                  Error Code 👈This is the picture This is the code for my ai👇

                                                                                              import datetime
                                                                                              import webbrowser
                                                                                              import pyttsx3
                                                                                              import pywhatkit
                                                                                              import speech_recognition
                                                                                              import wikipedia
                                                                                  
                                                                                              engine = pyttsx3.init("sapi5")
                                                                                              voices = engine.getProperty("voices")
                                                                                              engine.setProperty("voice", voices[0].id)
                                                                                              engine.setProperty("rate", 150)
                                                                                  
                                                                                  
                                                                                              def speak(audio):
                                                                                                  engine.say(audio)
                                                                                                  engine.runAndWait()
                                                                                  
                                                                                  
                                                                                              def takeCommand():
                                                                                                  r = speech_recognition.Recognizer()
                                                                                                  with speech_recognition.Microphone() as source:
                                                                                                      print("Listening...")
                                                                                                      r.pause_threshold = 4
                                                                                                      r.energy_threshold = 300
                                                                                                      audio = r.listen(source, 0, 4)
                                                                                  
                                                                                                  try:
                                                                                                      print("Understanding...")
                                                                                                      query = r.recognize_google(audio, language='en-us')
                                                                                                      print(f"You said: {query}\n")
                                                                                                  except Exception as e:
                                                                                                      print("Say that again")
                                                                                                      return "None"
                                                                                                  return query
                                                                                  
                                                                                  
                                                                                              # Starting...............................................................................................................
                                                                                              if __name__ == "__main__":
                                                                                                  while True:
                                                                                                      query = takeCommand().lower()
                                                                                                      if "wake up David" in query:
                                                                                                          hour = int(datetime.datetime.now().hour)
                                                                                                          if 0 <= hour <= 12:
                                                                                                              speak("Good Morning sir, how are you?")
                                                                                                          elif 12 < hour <= 18:
                                                                                                              speak("Good Afternoon sir, how are you?")
                                                                                  
                                                                                                          else:
                                                                                                              speak("Good Evening sir, how are you?")
                                                                                  
                                                                                                      while True:
                                                                                                          query = takeCommand().lower()
                                                                                                          if "go to sleep david" in query:
                                                                                                              speak("Ok, See you, Remember if you need anything just say, wake up david")
                                                                                                              break
                                                                                  
                                                                                                          elif "I'm good how are you" in query:
                                                                                                              speak("I am also good, how may I help you today?")
                                                                                                          elif "thank you" in query:
                                                                                                              speak("You are welcome sir")
                                                                                  
                                                                                  
                                                                                              # Web browser searching..................................................................................................
                                                                                  
                                                                                                          def searchGoogle(query):
                                                                                                              if "google" in query:
                                                                                                                  import wikipedia as googleScrap
                                                                                                                  query = query.replace("david", "")
                                                                                                                  query = query.replace("google search", "")
                                                                                                                  query = query.replace("google", "")
                                                                                                                  speak("This is what I found")
                                                                                                                  try:
                                                                                                                      pywhatkit.search(query)
                                                                                                                      result = googleScrap.summary(query, 1)
                                                                                                                      speak(result)
                                                                                  
                                                                                                                  except:
                                                                                                                      speak("Did not find anything about that, sorry")
                                                                                  
                                                                                                  query = query.replace("jarvis", "")
                                                                                                  query = query.replace("google search", "")
                                                                                                  query = query.replace("google", "")
                                                                                                  speak("This is what I found on google")
                                                                                  
                                                                                                  try:
                                                                                                      pywhatkit.search(query)
                                                                                                      result = googleScrap.summary(query, 1)
                                                                                                      speak(result)
                                                                                  
                                                                                                  finally:
                                                                                                      speak("No speakable output available")
                                                                                  
                                                                                  
                                                                                              def searchYoutube(query):
                                                                                                  if "youtube" in query:
                                                                                                      speak("This is what I found for your search!")
                                                                                                      query = query.replace("youtube search", "")
                                                                                                      query = query.replace("youtube", "")
                                                                                                      query = query.replace("jarvis", "")
                                                                                                      web = "https://www.youtube.com/results?search_query=" + query
                                                                                                      webbrowser.open(web)
                                                                                                      pywhatkit.playonyt(query)
                                                                                                      speak("Done, Sir")
                                                                                  
                                                                                  
                                                                                              def searchWikipedia(query):
                                                                                                  if "wikipedia" in query:
                                                                                                      speak("Searching from wikipedia....")
                                                                                                      query = query.replace("wikipedia", "")
                                                                                                      query = query.replace("search wikipedia", "")
                                                                                                      query = query.replace("jarvis", "")
                                                                                                      results = wikipedia.summary(query,sentences=2)
                                                                                                      speak("According to wikipedia..")
                                                                                                      print(results)
                                                                                                      speak(results)
                                                                                  

                                                                                  These are the error codes I get

                                                                                  line 51, in query = takeCommand().lower()

                                                                                  line 25, in takeCommand audio = r.listen(source, 0, 4)

                                                                                  line 652, in listen buffer = source.stream.read(source.CHUNK)

                                                                                  line 161, in read return self.pyaudio_stream.read(size, exception_on_overflow=False)

                                                                                  line 608, in read return pa.read_stream(self._stream, num_frames, exception_on_overflow)

                                                                                  KeyboardInterrupt

                                                                                  Exception ignored on calling ctypes callback function: Traceback (most recent call last):

                                                                                  line 97, in call_with_this

                                                                                  line 1734, in isEnabledFor TypeError: 'NoneType' object is not callable

                                                                                  These are the modules I have installed:

                                                                                  import datetime import webbrowser import pyttsx3 import pywhatkit import speech_recognition import wikipedia

                                                                                  ANSWER

                                                                                  Answered 2022-Mar-10 at 05:33

                                                                                  replace your takeCommand() function with this:

                                                                                  def takeCommand():
                                                                                  r = speech_recognition.Recognizer()
                                                                                  with speech_recognition.Microphone() as source:
                                                                                      speech_recognition.Recognizer().adjust_for_ambient_noise(source, duration=0.2)
                                                                                      print("Listening...")
                                                                                      audio = r.listen(source)
                                                                                  
                                                                                      try:
                                                                                          query = r.recognize_google(audio, language='en-in')
                                                                                          print(f"user said:{query}\n")
                                                                                  
                                                                                      except Exception as e:
                                                                                          return "None"
                                                                                      return query
                                                                                  

                                                                                  Other than this there are no other errors in your code and for the web scraping functions. You are not actually calling them

                                                                                  Update

                                                                                  engine = pyttsx3.init("sapi5")
                                                                                  voices = engine.getProperty("voices")
                                                                                  engine.setProperty("voice", voices[0].id)
                                                                                  engine.setProperty("rate", 150)
                                                                                  
                                                                                  
                                                                                  def speak(audio):
                                                                                      engine.say(audio)
                                                                                      engine.runAndWait()
                                                                                  
                                                                                  
                                                                                  def takeCommand():
                                                                                      r = speech_recognition.Recognizer()
                                                                                      with speech_recognition.Microphone() as source:
                                                                                          print("Listening...")
                                                                                          r.pause_threshold = 4
                                                                                          r.energy_threshold = 300
                                                                                          audio = r.listen(source, 0, 4)
                                                                                  
                                                                                      try:
                                                                                          print("Understanding...")
                                                                                          query = r.recognize_google(audio, language='en-us')
                                                                                          print(f"You said: {query}\n")
                                                                                      except Exception as e:
                                                                                          print("Say that again")
                                                                                          return "None"
                                                                                      return query
                                                                                  
                                                                                  def searchGoogle(query):
                                                                                      import wikipedia as googleScrap
                                                                                      speak("This is what I found")
                                                                                      try:
                                                                                          pywhatkit.search(query)
                                                                                          result = googleScrap.summary(query, 1)
                                                                                          speak(result)
                                                                                  
                                                                                      except:
                                                                                          speak("Did not find anything about that, sorry")
                                                                                  
                                                                                  
                                                                                  def searchYoutube(query):
                                                                                      web = "https://www.youtube.com/results?search_query=" + query
                                                                                      webbrowser.open(web)
                                                                                      pywhatkit.playonyt(query)
                                                                                      speak("Done, Sir")
                                                                                  
                                                                                  
                                                                                  def searchWikipedia(query):
                                                                                      results = wikipedia.summary(query,sentences=2)
                                                                                      speak("According to wikipedia..")
                                                                                      print(results)
                                                                                      speak(results)
                                                                                  
                                                                                  
                                                                                  # Starting...............................................................................................................
                                                                                  if __name__ == "__main__":
                                                                                      while True:
                                                                                          query = takeCommand().lower()
                                                                                          if "wake up David" in query:
                                                                                              hour = int(datetime.datetime.now().hour)
                                                                                              if 0 <= hour <= 12:
                                                                                                  speak("Good Morning sir, how are you?")
                                                                                              elif 12 < hour <= 18:
                                                                                                  speak("Good Afternoon sir, how are you?")
                                                                                  
                                                                                              else:
                                                                                                  speak("Good Evening sir, how are you?")
                                                                                  
                                                                                          while True:
                                                                                              query = takeCommand().lower()
                                                                                              if "go to sleep david" in query:
                                                                                                  speak("Ok, See you, Remember if you need anything just say, wake up david")
                                                                                                  break
                                                                                  
                                                                                              elif "I'm good how are you" in query:
                                                                                                  speak("I am also good, how may I help you today?")
                                                                                  
                                                                                              elif "thank you" in query:
                                                                                                  speak("You are welcome sir")
                                                                                  
                                                                                              elif "wikipedia" in query:
                                                                                                  speak("Searching from wikipedia....")
                                                                                                  query = query.replace("wikipedia", "")
                                                                                                  query = query.replace("search wikipedia", "")
                                                                                                  query = query.replace("jarvis", "")
                                                                                                  searchWikipedia(query)
                                                                                  
                                                                                              elif "youtube" in query:
                                                                                                  speak("This is what I found for your search!")
                                                                                                  query = query.replace("youtube search", "")
                                                                                                  query = query.replace("youtube", "")
                                                                                                  query = query.replace("jarvis", "")
                                                                                                  searchYoutube(query)
                                                                                              
                                                                                              elif "google" in query:
                                                                                                  query = query.replace("david", "")
                                                                                                  query = query.replace("google search", "")
                                                                                                  query = query.replace("google", "")
                                                                                                  searchGoogle(query)
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/71389304

                                                                                  QUESTION

                                                                                  Build a voice assistant to open the application with a path in the curly bracket
                                                                                  Asked 2022-Mar-06 at 15:39

                                                                                  I wondered if I could add a lot of paths to open the application, but my code only opens the calculator when I ask to open chrome. It shows me like this The file /System/Applications/Google Chrome.app does not exist. Suppose you want to fix my code to be better. I am on a mac, by the way. Thank you.

                                                                                  my code:

                                                                                  import speech_recognition as sr
                                                                                  from gtts import gTTS
                                                                                  import playsound
                                                                                  import os
                                                                                  import subprocess as sp
                                                                                  import random
                                                                                  
                                                                                  def take_command():
                                                                                      r = sr.Recognizer()
                                                                                      with sr.Microphone() as source:
                                                                                          r.adjust_for_ambient_noise(source, duration=1)
                                                                                          print('listening...')
                                                                                          audio = r.listen(source)
                                                                                          try:
                                                                                              text = r.recognize_google(audio)
                                                                                              text = text.lower()
                                                                                              print(f"user: {text}")  # print user app said
                                                                                          except sr.UnknownValueError:
                                                                                              speak('Sorry, I did not get that')
                                                                                              text = None
                                                                                          except sr.RequestError:
                                                                                              speak('Request error')
                                                                                              text = None
                                                                                          return text
                                                                                  
                                                                                  
                                                                                  def speak(audio_string):
                                                                                      tts = gTTS(text=audio_string, lang='en-uk', slow=False)  # text to speech(voice)
                                                                                      recognizer = random.randint(1, 20000000)
                                                                                      audio_file = 'audio' + str(recognizer) + '.mp3'
                                                                                      tts.save(audio_file)  # save as mp3
                                                                                      print('\33[1m' f"computer: {audio_string}")  # print what app said
                                                                                      playsound.playsound(audio_file)  # play the audio file
                                                                                      os.remove(audio_file)  # remove audio file
                                                                                  
                                                                                  
                                                                                  paths = {
                                                                                      "chrome": ['open', '/System/Applications/Google Chrome.app'],
                                                                                      "excel": ['open', '/System/Applications/Microsoft Excel.app'],
                                                                                      "calculator": ['open', '/System/Applications/Calculator.app'],
                                                                                  }
                                                                                  
                                                                                  
                                                                                  if __name__ == '__main__':
                                                                                      while True:
                                                                                          query = take_command()
                                                                                  
                                                                                          if str(query) in paths:
                                                                                              app = paths.get(query)
                                                                                              sp.call(app)
                                                                                  
                                                                                          elif 'bye' in str(query):
                                                                                              exit()
                                                                                          
                                                                                          else:
                                                                                              speak('Please repeat the command.')
                                                                                  

                                                                                  terminal:

                                                                                  listening...
                                                                                  user: chrome
                                                                                  The file /System/Applications/Google Chrome.app does not exist.
                                                                                  listening...
                                                                                  user: calculator
                                                                                  listening...
                                                                                  user: bye
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2022-Mar-06 at 15:39

                                                                                  Try specifying the Chrome Path as:

                                                                                  paths = {
                                                                                      "chrome": ['open', '/Applications/Google Chrome.app'],
                                                                                      "excel": ['open', '/System/Applications/Microsoft Excel.app'],
                                                                                      "calculator": ['open', '/System/Applications/Calculator.app'],
                                                                                  }
                                                                                  

                                                                                  This is the default chrome install location.

                                                                                  Source https://stackoverflow.com/questions/71371642

                                                                                  QUESTION

                                                                                  How to open wa.me link directly on Whastapp desktop application, rather than it redirecting to web (on PC)?
                                                                                  Asked 2022-Mar-02 at 14:32

                                                                                  I am writing a Python script (3.10.2) which opens certain desktop applications via voice command using the pyttsx3 and speech_recognition modules.

                                                                                  I thought of including Whatsapp into this script as well, and provided the wa.me chat link of one of my whatsapp contacts, which would open after a certain voice command is said.

                                                                                  However, the problem lies when it opens the link, instead of directly opening it on the Whatsapp desktop application (already downloaded from MSStore) it redirects itself to the web and then the prompt asks if to continue on web or to open the desktop application.

                                                                                  I want to make it, directly opening the application, rather than going through the web prompts. Is there a way?

                                                                                  Thanks in advance!

                                                                                  ANSWER

                                                                                  Answered 2022-Mar-02 at 14:32

                                                                                  Ok, here. There are two ways one is this:

                                                                                  import subprocess
                                                                                  
                                                                                  subprocess.Popen("C:\\Windows\\System32\\whatsapp.exe")
                                                                                  

                                                                                  Another is this:

                                                                                  import os
                                                                                  os.system("program_name")
                                                                                  

                                                                                  Source https://stackoverflow.com/questions/71320853

                                                                                  QUESTION

                                                                                  IndexError: tuple index out of range when I try to create an executable from a python script using auto-py-to-exe
                                                                                  Asked 2022-Feb-24 at 15:03

                                                                                  I have been trying out an open-sourced personal AI assistant script. The script works fine but I want to create an executable so that I can gift the executable to one of my friends. However, when I try to create the executable using the auto-py-to-exe, it states the below error:

                                                                                  Running auto-py-to-exe v2.10.1
                                                                                  Building directory: C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x
                                                                                  Provided command: pyinstaller --noconfirm --onedir --console --no-embed-manifest  "C:/Users/Tarun/AppData/Local/Programs/Python/Python310/AI_Ass.py"
                                                                                  Recursion Limit is set to 5000
                                                                                  Executing: pyinstaller --noconfirm --onedir --console --no-embed-manifest C:/Users/Tarun/AppData/Local/Programs/Python/Python310/AI_Ass.py --distpath C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x\application --workpath C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x\build --specpath C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x
                                                                                  
                                                                                  42681 INFO: PyInstaller: 4.6
                                                                                  42690 INFO: Python: 3.10.0
                                                                                  42732 INFO: Platform: Windows-10-10.0.19042-SP0
                                                                                  42744 INFO: wrote C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x\AI_Ass.spec
                                                                                  42764 INFO: UPX is not available.
                                                                                  42772 INFO: Extending PYTHONPATH with paths
                                                                                  ['C:\\Users\\Tarun\\AppData\\Local\\Programs\\Python\\Python310']
                                                                                  43887 INFO: checking Analysis
                                                                                  43891 INFO: Building Analysis because Analysis-00.toc is non existent
                                                                                  43895 INFO: Initializing module dependency graph...
                                                                                  43915 INFO: Caching module graph hooks...
                                                                                  43975 INFO: Analyzing base_library.zip ...
                                                                                  54298 INFO: Processing pre-find module path hook distutils from 'C:\\Users\\Tarun\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
                                                                                  54306 INFO: distutils: retargeting to non-venv dir 'C:\\Users\\Tarun\\AppData\\Local\\Programs\\Python\\Python310\\lib'
                                                                                  57474 INFO: Caching module dependency graph...
                                                                                  58088 INFO: running Analysis Analysis-00.toc
                                                                                  58132 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
                                                                                    required by C:\Users\Tarun\AppData\Local\Programs\Python\Python310\python.exe
                                                                                  58365 INFO: Analyzing C:\Users\Tarun\AppData\Local\Programs\Python\Python310\AI_Ass.py
                                                                                  59641 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'C:\\Users\\Tarun\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-urllib3.packages.six.moves.py'.
                                                                                  An error occurred while packaging
                                                                                  Traceback (most recent call last):
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\auto_py_to_exe\packaging.py", line 131, in package
                                                                                      run_pyinstaller()
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\__main__.py", line 124, in run
                                                                                      run_build(pyi_config, spec_file, **vars(args))
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\__main__.py", line 58, in run_build
                                                                                      PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 782, in main
                                                                                      build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 714, in build
                                                                                      exec(code, spec_namespace)
                                                                                    File "C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x\AI_Ass.spec", line 7, in 
                                                                                      a = Analysis(['C:/Users/Tarun/AppData/Local/Programs/Python/Python310/AI_Ass.py'],
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 277, in __init__
                                                                                      self.__postinit__()
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\datastruct.py", line 155, in __postinit__
                                                                                      self.assemble()
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 439, in assemble
                                                                                      priority_scripts.append(self.graph.add_script(script))
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 265, in add_script
                                                                                      self._top_script_node = super().add_script(pathname)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1433, in add_script
                                                                                      self._process_imports(n)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
                                                                                      target_module = self._safe_import_hook(*import_info, **kwargs)[0]
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook
                                                                                      target_modules = self.import_hook(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1505, in import_hook
                                                                                      target_package, target_module_partname = self._find_head_package(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1684, in _find_head_package
                                                                                      target_package = self._safe_import_module(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module
                                                                                      return super()._safe_import_module(module_basename, module_name, parent_package)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module
                                                                                      self._process_imports(n)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
                                                                                      target_module = self._safe_import_hook(*import_info, **kwargs)[0]
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook
                                                                                      target_modules = self.import_hook(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1505, in import_hook
                                                                                      target_package, target_module_partname = self._find_head_package(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1684, in _find_head_package
                                                                                      target_package = self._safe_import_module(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module
                                                                                      return super()._safe_import_module(module_basename, module_name, parent_package)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module
                                                                                      self._process_imports(n)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
                                                                                      target_module = self._safe_import_hook(*import_info, **kwargs)[0]
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook
                                                                                      target_modules = self.import_hook(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1505, in import_hook
                                                                                      target_package, target_module_partname = self._find_head_package(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1684, in _find_head_package
                                                                                      target_package = self._safe_import_module(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module
                                                                                      return super()._safe_import_module(module_basename, module_name, parent_package)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module
                                                                                      self._process_imports(n)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
                                                                                      target_module = self._safe_import_hook(*import_info, **kwargs)[0]
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook
                                                                                      target_modules = self.import_hook(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1505, in import_hook
                                                                                      target_package, target_module_partname = self._find_head_package(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1684, in _find_head_package
                                                                                      target_package = self._safe_import_module(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module
                                                                                      return super()._safe_import_module(module_basename, module_name, parent_package)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module
                                                                                      self._process_imports(n)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
                                                                                      target_module = self._safe_import_hook(*import_info, **kwargs)[0]
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook
                                                                                      target_modules = self.import_hook(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1518, in import_hook
                                                                                      submodule = self._safe_import_module(head, mname, submodule)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module
                                                                                      return super()._safe_import_module(module_basename, module_name, parent_package)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module
                                                                                      self._process_imports(n)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
                                                                                      target_module = self._safe_import_hook(*import_info, **kwargs)[0]
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook
                                                                                      target_modules = self.import_hook(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1518, in import_hook
                                                                                      submodule = self._safe_import_module(head, mname, submodule)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module
                                                                                      return super()._safe_import_module(module_basename, module_name, parent_package)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module
                                                                                      self._process_imports(n)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports
                                                                                      target_module = self._safe_import_hook(*import_info, **kwargs)[0]
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook
                                                                                      target_modules = self.import_hook(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1518, in import_hook
                                                                                      submodule = self._safe_import_module(head, mname, submodule)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module
                                                                                      return super()._safe_import_module(module_basename, module_name, parent_package)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2061, in _safe_import_module
                                                                                      n = self._scan_code(module, co, co_ast)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2645, in _scan_code
                                                                                      self._scan_bytecode(
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2749, in _scan_bytecode
                                                                                      for inst in util.iterate_instructions(module_code_object):
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\util.py", line 147, in iterate_instructions
                                                                                      yield from iterate_instructions(constant)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\util.py", line 139, in iterate_instructions
                                                                                      yield from get_instructions(code_object)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\dis.py", line 338, in _get_instructions_bytes
                                                                                      argval, argrepr = _get_const_info(arg, constants)
                                                                                    File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\dis.py", line 292, in _get_const_info
                                                                                      argval = const_list[const_index]
                                                                                  IndexError: tuple index out of range
                                                                                  
                                                                                  Project output will not be moved to output folder
                                                                                  Complete.
                                                                                  

                                                                                  I understand that there is a thread already about similar issue but it still doesn't solve the issue. Hence seeking out help

                                                                                  I really have no idea why is the error occurring and how to resolve it. I am pasting the script below for your reference. Can some one please help? Thank you in advance

                                                                                  #importing libraries
                                                                                  
                                                                                  import speech_recognition as sr
                                                                                  import pyttsx3
                                                                                  import datetime
                                                                                  import wikipedia
                                                                                  import webbrowser
                                                                                  import os
                                                                                  import time
                                                                                  import subprocess
                                                                                  from   ecapture import ecapture as ec
                                                                                  import wolframalpha
                                                                                  import json
                                                                                  import requests
                                                                                  
                                                                                  #setting up speech engine
                                                                                  engine=pyttsx3.init('sapi5')
                                                                                  voices=engine.getProperty('voices')
                                                                                  engine.setProperty('voice','voices[1].id')
                                                                                  
                                                                                  def speak(text):
                                                                                      engine.say(text)
                                                                                      engine.runAndWait()
                                                                                      
                                                                                  #Greet user
                                                                                  def wishMe():
                                                                                      hour=datetime.datetime.now().hour
                                                                                      if hour>=0 and hour<12:
                                                                                          speak("Hello,Good Morning")
                                                                                          print("Hello,Good Morning")
                                                                                      elif hour>=12 and hour<18:
                                                                                          speak("Hello,Good Afternoon")
                                                                                          print("Hello,Good Afternoon")
                                                                                      else:
                                                                                          speak("Hello,Good Evening")
                                                                                          print("Hello,Good Evening")
                                                                                  
                                                                                  #Setting up the command function for your AI assistant
                                                                                  def takeCommand():
                                                                                      r=sr.Recognizer()
                                                                                      with sr.Microphone() as source:
                                                                                          print("Listening...")
                                                                                          audio=r.listen(source)
                                                                                  
                                                                                          try:
                                                                                              statement=r.recognize_google(audio,language='en-in')
                                                                                              print(f"user said:{statement}\n")
                                                                                  
                                                                                          except Exception as e:
                                                                                              speak("Pardon me, please say that again")
                                                                                              return "None"
                                                                                          return statement
                                                                                  
                                                                                  print("Loading your AI personal assistant Friday")
                                                                                  speak("Loading your AI personal assistant Friday")
                                                                                  wishMe()
                                                                                  
                                                                                  #main function
                                                                                  if __name__=='__main__':
                                                                                  
                                                                                  
                                                                                      while True:
                                                                                          speak("Tell me how can I help you now?")
                                                                                          statement = takeCommand().lower()
                                                                                          if statement==0:
                                                                                              continue
                                                                                  
                                                                                          if "good bye" in statement or "ok bye" in statement or "stop" in statement:
                                                                                              speak('your personal assistant Friday is shutting down,Good bye')
                                                                                              print('your personal assistant Friday is shutting down,Good bye')
                                                                                              break
                                                                                  
                                                                                  
                                                                                          if 'wikipedia' in statement:
                                                                                              speak('Searching Wikipedia...')
                                                                                              statement =statement.replace("wikipedia", "")
                                                                                              results = wikipedia.summary(statement, sentences=10)
                                                                                              webbrowser.open_new_tab("https://en.wikipedia.org/wiki/"+ statement)
                                                                                              speak("According to Wikipedia")
                                                                                              print(results)
                                                                                              speak(results)
                                                                                  
                                                                                          elif 'open youtube' in statement:
                                                                                              webbrowser.register('chrome', None,
                                                                                          webbrowser.BackgroundBrowser("C://Program Files (x86)//Google//Chrome//Application//chrome.exe"))
                                                                                              webbrowser.get('chrome').open_new_tab("https://www.youtube.com")
                                                                                              #webbrowser.open_new_tab("https://www.youtube.com")
                                                                                              speak("youtube is open now")
                                                                                              time.sleep(5)
                                                                                  
                                                                                          elif 'open google' in statement:
                                                                                              webbrowser.open_new_tab("https://www.google.com")
                                                                                              speak("Google chrome is open now")
                                                                                              time.sleep(5)
                                                                                  
                                                                                          elif 'open gmail' in statement:
                                                                                              webbrowser.open_new_tab("gmail.com")
                                                                                              speak("Google Mail open now")
                                                                                              time.sleep(5)
                                                                                          
                                                                                          elif 'time' in statement:
                                                                                              strTime=datetime.datetime.now().strftime("%H:%M:%S")
                                                                                              speak(f"the time is {strTime}")
                                                                                  
                                                                                          elif 'news' in statement:
                                                                                              news = webbrowser.open_new_tab("https://timesofindia.indiatimes.com/home/headlines")
                                                                                              speak('Here are some headlines from the Times of India,Happy reading')
                                                                                              time.sleep(6)
                                                                                  
                                                                                          elif "camera" in statement or "take a photo" in statement:
                                                                                              ec.capture(0,"robo camera","img.jpg")
                                                                                  
                                                                                          elif 'search' in statement:
                                                                                              statement = statement.replace("search", "")
                                                                                              webbrowser.open_new_tab(statement)
                                                                                              time.sleep(5)
                                                                                  
                                                                                          elif 'who are you' in statement or 'what can you do' in statement:
                                                                                              speak('I am Friday version 1 point O your personal assistant. I am programmed to minor tasks like'
                                                                                              'opening youtube,google chrome, gmail and stackoverflow ,predict time,take a photo,search wikipedia,predict weather' 
                                                                                              'In different cities, get top headline news from times of india and you can ask me computational or geographical questions too!')
                                                                                  
                                                                                  
                                                                                          elif "who made you" in statement or "who created you" in statement or "who discovered you" in statement:
                                                                                              speak("I was built by Mirthula")
                                                                                              print("I was built by Mirthula")
                                                                                  
                                                                                          elif "log off" in statement or "sign out" in statement:
                                                                                              speak("Ok , your pc will log off in 10 sec make sure you exit from all applications")
                                                                                              subprocess.call(["shutdown", "/l"])
                                                                                              
                                                                                  time.sleep(3)
                                                                                  

                                                                                  ANSWER

                                                                                  Answered 2021-Nov-05 at 02:20
                                                                                  42681 INFO: PyInstaller: 4.6
                                                                                  42690 INFO: Python: 3.10.0
                                                                                  

                                                                                  There's the issue. Python 3.10.0 has a bug with PyInstaller 4.6. The problem isn't you or PyInstaller. Try converting it using Python 3.9.7 instead. Ironic, considering 3.10.0 was suppose to be a bugfix update.

                                                                                  Source https://stackoverflow.com/questions/69776492

                                                                                  QUESTION

                                                                                  No Audio with pyttsx3 Library in Python 3 (No errors)
                                                                                  Asked 2022-Feb-23 at 19:25

                                                                                  Using pyttsx3 (tried versions 2.5 to current) on Visual Studios Code on Windows 10 With Python 3.10.0. My Problem that I am currently having is that the code will run through, but no audio is being outputted. while debugging there is no pause stepping into or over the code (for parts including pyttsx3). I made sure my audio is on, and that it is working. I used a different tts library gtts and the audio worked, but I am trying to write offline. I also tried this exact code from VS code in PyCharm and I still had the same problem. Again with no errors or warnings.

                                                                                  import speech_recognition as sr
                                                                                  import pyttsx3
                                                                                  
                                                                                  
                                                                                  listener = sr.Recognizer()
                                                                                  engine = pyttsx3.init(driverName='sapi5')
                                                                                  #voices = engine.getProperty('voices')
                                                                                  #engine.setProperty('voice', voices[0].id)
                                                                                  engine.say("Testing, audio")
                                                                                  engine.runAndWait
                                                                                  
                                                                                  try:
                                                                                      with sr.Microphone() as source:
                                                                                          print('Listening...')
                                                                                          voice = listener.listen(source)
                                                                                          command = listener.recognize_google(voice)
                                                                                          print(command)
                                                                                          engine.say(command)
                                                                                          engine.runAndWait
                                                                                  except:
                                                                                      pass
                                                                                  
                                                                                  print('Hello')
                                                                                  

                                                                                  I also tried this block of code with no driver name and the same problem above persists

                                                                                  import speech_recognition as sr
                                                                                  import pyttsx3
                                                                                  
                                                                                  
                                                                                  listener = sr.Recognizer()
                                                                                  engine = pyttsx3.init()
                                                                                  #voices = engine.getProperty('voices')
                                                                                  #engine.setProperty('voice', voices[0].id)
                                                                                  engine.say("Testing, audio")
                                                                                  engine.runAndWait
                                                                                  
                                                                                  try:
                                                                                      with sr.Microphone() as source:
                                                                                          print('Listening...')
                                                                                          voice = listener.listen(source)
                                                                                          command = listener.recognize_google(voice)
                                                                                          print(command)
                                                                                          engine.say(command)
                                                                                          engine.runAndWait
                                                                                  except:
                                                                                      pass
                                                                                  
                                                                                  print('Hello')
                                                                                  

                                                                                  The two commented lines on both programs didn't change anything for me either. I also tested the program with just pyttsx3.

                                                                                  import pyttsx3
                                                                                  
                                                                                  engine = pyttsx3.init(driverName='sapi5')
                                                                                  engine.say("Testing, audio")
                                                                                  engine.runAndWait
                                                                                  

                                                                                  and tested using 'Testing, audio' instead of "Testing, audio" and I tried single words as well.

                                                                                  Any help would be amazing! Thank you! In the mean time I will try to test this(translated to work with Linux) program in Linux to see if my OS is the issue. I will also try an older version of python to see if that is the issue. Along with python 2. My biggest assumption is that pyttsx3 needs a earlier version of python to work, but I could also be 100% wrong about that.

                                                                                  ANSWER

                                                                                  Answered 2022-Feb-23 at 19:25

                                                                                  You forgot to put the parentheses on engine.runAndWait. Do this: engine.runAndWait()

                                                                                  Source https://stackoverflow.com/questions/71230103

                                                                                  QUESTION

                                                                                  How to close all the processes one by one in a program that operates with multiprocessing by means of an 'if' validation found in one of them process?
                                                                                  Asked 2022-Feb-12 at 20:25
                                                                                  import multiprocessing
                                                                                  from threading import Thread
                                                                                  import speech_recognition as sr
                                                                                  
                                                                                  def actions_func(conn1_3,conn2_3):
                                                                                  
                                                                                  def capture_cam(conn1, conn1b):
                                                                                  
                                                                                  def audio_listening(conn2, conn2b):
                                                                                      global catch_current_frame
                                                                                      catch_current_frame = False
                                                                                  
                                                                                      # start dameon thread to handle frame requests:
                                                                                      Thread(target=handle_catch_current_frame_requests, args=(conn2,), daemon=True).start()
                                                                                      Thread(target=handle_cam_activate_requests, args=(conn2b,), daemon=True).start()
                                                                                  
                                                                                      while True:
                                                                                          r = sr.Recognizer()
                                                                                  
                                                                                          with sr.Microphone() as source:
                                                                                              catch_current_frame = False
                                                                                              r.adjust_for_ambient_noise(source)
                                                                                              print("Please say something...")
                                                                                              audio = r.listen(source)
                                                                                  
                                                                                              try:
                                                                                                  text = r.recognize_google(audio, language="es-ES")
                                                                                                  print("You have said: \n " + repr(text))
                                                                                  
                                                                                                  #Verifications
                                                                                                  if text.lower() == "capture":
                                                                                                      catch_current_frame = True
                                                                                                  elif text.lower() == "Close your program":
                                                                                                      #This is where I need to close processes p1, p2 and p3
                                                                                                      break
                                                                                                  else:
                                                                                                      pass
                                                                                  
                                                                                              except Exception as e:
                                                                                                  print("Error : " + str(e))
                                                                                  
                                                                                  
                                                                                  def main_process(finish_state):
                                                                                      conn1, conn1_3 = multiprocessing.Pipe(duplex=True)
                                                                                      conn2, conn2_3 = multiprocessing.Pipe(duplex=True)
                                                                                      conn1b, conn2b = multiprocessing.Pipe(duplex=True)
                                                                                  
                                                                                      #Process 1
                                                                                      p1 = multiprocessing.Process(target=capture_cam, args=(conn1, conn1b, ))
                                                                                      p1.start()
                                                                                      #Process 2
                                                                                      p2 = multiprocessing.Process(target=audio_listening, args=(conn2, conn2b, ))
                                                                                      p2.start()
                                                                                      #Process 3
                                                                                      p3 = multiprocessing.Process(target=actions_func, args=(conn1_3 ,conn2_3 ,))
                                                                                      p3.start()
                                                                                  
                                                                                  if __name__ == '__main__':
                                                                                      finish_state = multiprocessing.Event()
                                                                                      main_process(finish_state)
                                                                                  
                                                                                  print("continue the code... ")
                                                                                  
                                                                                  

                                                                                  I need that when the variable text is equal to "Close your program" the 3 active processes(p1,p2,p3) are closed.

                                                                                  I have tried to do something like this:

                                                                                  elif text.lower() == "Close your program":
                                                                                      print("the process has been interrupted!")
                                                                                      finish_state.set()
                                                                                      for process in [p1, p2, p3]:
                                                                                          process.terminate()
                                                                                  

                                                                                  But it is not working for me, and I would need a better code that allows me to close them one by one in that code block if text is equal to "Close your program".

                                                                                  What should I do so that under that condition all the processes are closed one by one?

                                                                                  ANSWER

                                                                                  Answered 2022-Feb-12 at 20:25

                                                                                  You could try the following Event-based solution (but there are even simpler solutions to follow):

                                                                                  Have main_process pass to audio_listening an additional argument, finish_state:

                                                                                  def main_process():
                                                                                      conn1, conn1_3 = multiprocessing.Pipe(duplex=True)
                                                                                      conn2, conn2_3 = multiprocessing.Pipe(duplex=True)
                                                                                      conn1b, conn2b = multiprocessing.Pipe(duplex=True)
                                                                                  
                                                                                      #Process 1
                                                                                      p1 = multiprocessing.Process(target=capture_cam, args=(conn1, conn1b, ))
                                                                                      p1.start()
                                                                                      #Process 2
                                                                                      finish_state = multiprocessing.Event()
                                                                                      p2 = multiprocessing.Process(target=audio_listening, args=(conn2, conn2b, finish_state))
                                                                                      p2.start()
                                                                                      #Process 3
                                                                                      p3 = multiprocessing.Process(target=actions_func, args=(conn1_3 ,conn2_3 ,))
                                                                                      p3.start()
                                                                                  
                                                                                      finish_state.wait()
                                                                                      p1.terminate()
                                                                                      p2.terminate() # Not really necessary since the process is ending by itself
                                                                                      p3.terminate()
                                                                                  
                                                                                  if __name__ == '__main__':
                                                                                      main_process()
                                                                                  

                                                                                  Note that it is now main_process that is creating the finish_state multiprocessing.Event instance; there appears to be no need for it to be passed as an argument. When the event is set, the main process will terminate the subprocesses that it has created.

                                                                                  Then in audio_processing:

                                                                                  def audio_listening(conn2, conn2b, finish_state):
                                                                                      ...
                                                                                                  if text.lower() == "capture":
                                                                                                      catch_current_frame = True
                                                                                                  elif text.lower() == "Close your program":
                                                                                                      # Set the finish state event:
                                                                                                      finish_state.set()
                                                                                                      break
                                                                                  

                                                                                  There are even two simpler alternatives that do not even require an Event variable:

                                                                                  The audio_process process is in an infinite loop until it either gets a "Close your program" message or it gets an exception. In both cases it terminates and presumably we then want the other two processes to terminate, also. Therefore, the main process can just issue a call to p2.join() after it has started all the other processes in order to wait for the audio_process process to complete and then either:

                                                                                  1. Call p1.terminate() followed by p3.terminate().
                                                                                  2. Or start processes p1 and p3 specifying daemon=True, e.g. p1 = multiprocessing.Process(target=capture_cam, args=(conn1, conn1b), daemon=True). Being daemon processes they will now automatically terminate as soon as the main process terminates. Therefore, there is no need to call terminate on these processes.

                                                                                  Source https://stackoverflow.com/questions/71094978

                                                                                  Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                                                                  Vulnerabilities

                                                                                  No vulnerabilities reported

                                                                                  Install speech_recognition

                                                                                  You can download it from GitHub.
                                                                                  You can use speech_recognition like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

                                                                                  Support

                                                                                  For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
                                                                                  Find more information at:
                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit
                                                                                  CLONE
                                                                                • HTTPS

                                                                                  https://github.com/Uberi/speech_recognition.git

                                                                                • CLI

                                                                                  gh repo clone Uberi/speech_recognition

                                                                                • sshUrl

                                                                                  git@github.com:Uberi/speech_recognition.git

                                                                                • Share this Page

                                                                                  share link

                                                                                  Explore Related Topics

                                                                                  Consider Popular Speech Libraries

                                                                                  DeepSpeech

                                                                                  by mozilla

                                                                                  kaldi

                                                                                  by kaldi-asr

                                                                                  zeal

                                                                                  by zealdocs

                                                                                  leon

                                                                                  by leon-ai

                                                                                  Try Top Libraries by Uberi

                                                                                  MotionTracking

                                                                                  by UberiPython

                                                                                  University-Notes

                                                                                  by UberiHTML

                                                                                  Adwear

                                                                                  by UberiPython

                                                                                  NicePhoneme

                                                                                  by UberiPython

                                                                                  Compare Speech Libraries with Highest Support

                                                                                  Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
                                                                                  Find more libraries
                                                                                  Explore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits​
                                                                                  Save this library and start creating your kit