Simple-Search-Assistant-Using-Python

Introduction:


  • Creating a simple voice assistant is easy in Python while comparing to other Programing Languages.
  • Python provide us many modules for making our work so simple and fast.
  • Here we are using speech recognition module and webbrowser module for our project.
  • speech recognition module is used to recognize our voice and convert that into text.
  • webbrowser module is used to open the browser and show the results based on our url input.
  • Here we are creating a voice-search assistant. based upon your voice command input it will open the browser and show the search result for you. 

Installation :
  • The command for installing speech recognition module on your machine is 
        pip install SpeechRecognition
             
  • The command for installing webbrowser module on your machine is
             pip install pycopy-webbrowser

        

  • After installation copy the source code and run it on your machine

 

             

Source Code :


 import speech_recognition as sr
 import webbrowser

 # create an instance of the recognizer class
 r = sr.Recognizer()

 # creating the instance of the Microphone class for using our microphone
 mic = sr.Microphone()

 with mic as source:

     print(" say something ")
 
     # adjust_for_ambient_noise() method of the Recognizer class is used to handle the ambient noise.
     r.adjust_for_ambient_noise(source)

     # listen() method captures input from the microphone
     # This method takes an audio source as its first argument and records input from the source until silence is detected.
     audio = r.listen(source)

     try:
         voice_data = r.recognize_google(audio)
         print(" you said : %s " %(voice_data))
         search_url = "https://www.google.com/search?q="+voice_data
         webbrowser.open_new_tab(search_url)

     except:
         print(" can't recognize your speech ")

 



Output :




  • For more Python Applications visit my Github site.
                                    click here --- github  
                                    


***********************************************************************************             



Post a Comment

0 Comments