{
    "componentChunkName": "component---src-templates-blog-post-js",
    "path": "/python-tutorial-creating-voice-assistant/",
    "result": {"data":{"site":{"siteMetadata":{"title":"CrewCode Solutions"}},"markdownRemark":{"id":"3797002a-529d-5f2b-8117-13367f479914","excerpt":"In this article i will explain you step by step how you can create voice assistant using python Step 1: Install necessary python library which gonna help in…","html":"<p>In this article i will explain you step by step how you can create voice assistant using python</p>\n<h4>Step 1: Install necessary python library which gonna help in creating voice assistant in python</h4>\n<ul>\n<li>Install pyttsx3 this is text to speech conversion library in python</li>\n</ul>\n<pre><code class=\"language-py\">   pip install pyttsx3\n</code></pre>\n<ul>\n<li>Install SpeechRecognition library this library will recognize our voice and convert to text</li>\n</ul>\n<pre><code class=\"language-py\">   pip install SpeechRecognition\n</code></pre>\n<ul>\n<li>Install webbrowser library this library helps in searching from google</li>\n</ul>\n<pre><code class=\"language-py\">   pip install webbrowser\n</code></pre>\n<ul>\n<li>Install pyaudio this library is dependency of SpeechRecognition API</li>\n</ul>\n<pre><code class=\"language-py\">  #To install on linux ubuntu\n\n  #To install pyaudio if you are using linux ubuntu run this command\n   sudo apt-get install portaudio19-dev python-pyaudio\n\n   #After running above command run the following command\n   sudo pip3 install PyAudio\n</code></pre>\n<pre><code class=\"language-py\">   # To install on windows and macos user\n   pip3 install pyaudio\n</code></pre>\n<h4>Step 2: Once all the library installed successfully copy paste following code</h4>\n<ul>\n<li>\n<p>Importing python library and initilizing pytsx3</p>\n<pre><code class=\"language-py\"> #importing all the required library\n import pyttsx3\n import speech_recognition as sr\n import webbrowser\n\n #initializing pyttsx3 and setting voice language as english\n engine = pyttsx3.init()\n voices = engine.getProperty('voices')\n en_voice_id = \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Speech\\Voices\\Tokens\\TTS_MS_EN-US_ZIRA_11.0\"\n engine.setProperty('voice', en_voice_id)\n</code></pre>\n</li>\n<li>\n<p>Defining function which we would call on the basis of required work to be done</p>\n<pre><code class=\"language-py\">   #this function would turn text to audio using pyAudio engine which we have initialized above\n   def audioOutput(audio):\n      engine.say(audio)\n      engine.runAndWait()\n\n   #this function would take audio input and convert it to text and return that text\n   def audioInput():\n       r = sr.Recognizer()\n       with sr.Microphone() as source:\n          print(\"Listening...\")\n\t         r.pause_threshold = 1\n\t         audio = r.listen(source)\n       try:\n\t         print(\"Recognizing...\")\n\t         query = r.recognize_google(audio, language ='en-in')\n\t         print(f\"User said: {query}\\n\")\n\n      except Exception as e:\n\t         print(e)\n\t         print(\"Unable to Recognize your voice.\")\n\t         return \"None\"\n      return query\n\n   #this function would be called first to welcome and greet user\n   def greetUser():\n       audioOutput(\"Hi, I am your Assistant, How may i help you today?\")\n\n\n   if __name__ == '__main__':\n       greetUser()\n       while True:\n          query = audioInput().lower()\n          if 'search on google' in query\n              speak(\"Searching on google\\n\")\n\t\t          webbrowser.open(\"google.com\")\n\n</code></pre>\n</li>\n</ul>","fields":{"slug":"/python-tutorial-creating-voice-assistant/"},"frontmatter":{"title":"Python tutorial creating voice assistant using python","date":"January 18, 2023","description":"In this article i will explain you step by step how you can create voice assistant using python","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/python.jpg"}},"previous":{"fields":{"slug":"/python-tutorial-converting-speech-to-text/"},"frontmatter":{"title":"Python tutorial converting speech to text using python script","date":"January 08, 2023","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/python.jpg"}},"next":{"fields":{"slug":"/python-tutorial-face-detection-using-webcam/"},"frontmatter":{"title":"Python tutorial creating voice assistant using python","date":"January 28, 2023","bannerimage":"https://crew-code-images.s3.us-east-1.amazonaws.com/blog_images/python.jpg"}}},"pageContext":{"id":"3797002a-529d-5f2b-8117-13367f479914","previousPostId":"1af3684c-e658-5671-9a2a-561a3e565085","nextPostId":"d3ac703f-7468-57c5-bc88-546f1f7768dd"}},
    "staticQueryHashes": ["3860684146"]}