How cool is it to make your own personal assistants like Alexa or Siri?It’s not terribly difficult and may be simply achieved in Python.Personal digital assistants ar capturing plenty of attention late.With growing advancements in AI, coaching the machines to tackle every day tasks is that the norm.Voice based mostly personal assistants have gained plenty of recognition during this era of sensible homes and sensible devices.These personal assistants may be simply organized to perform several of your regular tasks by merely giving voice commands.Google has popularized voice-based search that’s a boon for several like senior voters UN agency aren’t comfy mistreatment the keypad/keyboard.This article can walk you thru the steps to quickly develop a voice based mostly desktop assistant, Minchu (meaning Flash) that you just will deploy on any device.The necessity for developing this application is information of Python.For building any voice based mostly assistant you wish 2 main functions.One for being attentive to your commands and another to retort to your commands.together with these 2 core functions, you wish the tailored directions that you just can feed your assistant.The first step is to put in and import all the required libraries.Use pip install to put in the libraries before mercantilism them.Following ar a number of the key libraries utilized in this program:
  • The SpeechRecognition library permits Python to access audio from your system’s mike, transcribe the audio, and reserve it.
  • Google’s text-to-speech package, gTTS converts your audio inquiries to text.The response from the look-up perform that you simply write for attractive answer to the question is regenerate to an audio phrase by gTTS. This package interfaces with Google Translate’s API.
  • Playsound package is employed to grant voice to the solution. Playsound permits Python to play MP3 files. Web browser package provides a high-level interface that permits displaying Web-based pages to users.
  • Se is an alternative choice for displaying sites. However, for mistreatment this you would like to put in and supply the browser-specific net driver.

Implementation of the Personal Assistant

The entire code for this application is written in Python using libraries supported by Python.

Import required libraries:

import speech_recognition as sr #convert speech to text import datetime #for fetching date and time import wikipedia import webbrowser import requests import playsound # to play saved mp3 file from gtts import gTTS # google text to speech import os # to save/open files import wolframalpha # to calculate strings into formula from selenium import webdriver # to control browser operations

Write a function to capture your requests/questions:

def talk(): input=sr.Recognizer() with sr.Microphone() as source: audio=input.listen(source) data="" try: data=input.recognize_google(audio) print("Your question is, " + data) except sr.UnknownValueError: print("Sorry I did not hear your question, Please repeat again.") return data

Next, write a function to respond to your questions:

def respond(output): num=0 print(output) num += 1 response=gTTS(text=output, lang='en') file = str(num)+".mp3" playsound.playsound(file, True) os.remove(file)

Now write the module to add all the required customized responses to your questions:

if __name__=='__main__': respond("Hi, I am Minchu your personal desktop assistant") while(1): respond("How can I help you?") text=talk().lower() if text==0: continue if "stop" in str(text) or "exit" in str(text) or "bye" in str(text): respond("Ok bye and take care") break if 'wikipedia' in text: respond('Searching Wikipedia') text =text.replace("wikipedia", "") results = wikipedia.summary(text, sentences=3) respond("According to Wikipedia") print(results) respond(results) elif 'time' in text:"%H:%M:%S") respond(f"the time is {strTime}") elif 'search' in text: text = text.replace("search", "") webbrowser.open_new_tab(text) time.sleep(5) elif "calculate" or "what is" in text: question=talk() app_id="Mention your API Key" client = wolframalpha.Client(app_id) res = client.query(question) answer = next(res.results).text respond("The answer is " + answer) elif 'open googlr' in text: webbrowser.open_new_tab("") respond("Google is open") time.sleep(5) elif 'youtube' in text: driver = webdriver.Chrome(r"Mention your webdriver location") driver.implicitly_wait(1) driver.maximize_window() respond("Opening in youtube") indx = text.split().index('youtube') query = text.split()[indx + 1:] driver.get(" =" + '+'.join(query)) elif "open word" in text: respond("Opening Microsoft Word") os.startfile('Mention location of Word in your system') else: respond("Application not available")
Once all the modules of your program ar prepared, execute may be excited to listen to your own personal assistant converse with’ll be able to add additional customizations supported your necessities, and develop a really intuitive voice based mostly assistant.Once your desktop assistant is prepared it’s time to deploy’ll be able to convert it into associate feasible file and run it on any device.

Generate an executable for your voice assistant

To create associate degree workable from the Python script you’ll be able to use Pyinstaller.First, you’ve got to convert the .ipynb Python file to a .py extension.Next, use Pyinstaller to make a .exe file for your .py file.All the subsequent steps got to be performed within the electronic communication from the situation wherever Python is installed:
pip install ipython pip install nbconvert pip install pyinstalleripython nbconvert --to script minchu.ipynb #mention .ipynb file name to convert to .pypyinstaller #builds .exe file
The .py file created ought to be settled within the same folder wherever the .ipynb file is found.Once the build is complete, Pyinstaller creates 2 folders, build and dist.Navigate to the dist folder and execute the .exe file to run your personal desktop assistant.This application is transportable and may be dead on any device.


This is however easy it’s to create your own voice’ll add more options like play your favorite songs, offer weather details, open email application, compose emails, restart your system,’ll integrate this application into your phone or pill yet.