Akhila
Published © GPL3+

Desktop Voice Assistant

Project is about the desktop voice assistant. It does various tasks like browsing the web, home automation and many more.

IntermediateFull instructions provided3 hours732
Desktop Voice Assistant

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Relay Module (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
mobile charger
×1
LED Light Bulb, Frosted GLS
LED Light Bulb, Frosted GLS
I demonstrated using the bulb. You can more devices to the relay for complete home automation
×1

Software apps and online services

Visual Studio 2017
Microsoft Visual Studio 2017
Any other python platform can be used
SMS Messaging API
Twilio SMS Messaging API
mailgun

Hand tools and fabrication machines

Multitool, Screwdriver
Multitool, Screwdriver

Story

Read more

Custom parts and enclosures

Demontration

I used a single led bulb

Schematics

Home Automation

This is the circuit diagram. you can use it as a reference for circuit connections.

Code

Desktop Code

Python
Voice assistant is developed using the python programming language. You can run the code at any python platform like Visualstudio, IDLE, Jupyter etc
import pyttsx3 #pip install pyttsx3
import speech_recognition as sr #pyaudio
import datetime
import wikipedia 
import webbrowser
import os, sys
import smtplib
from boltiot import Sms,Email,Bolt 
import json, time

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id) 
MAILGUN_API_KEY = 'This is the private API key which you can find on your Mailgun Dashboard' 
SANDBOX_URL= 'You can find this on your Mailgun Dashboard' 
SENDER_EMAIL = 'test@' + SANDBOX_URL  # No need to modify this. The sandbox URL is of the format test@YOUR_SANDBOX_URL
RECIPIENT_EMAIL = 'Enter your Email ID Here'
SID = 'You can find SID in your Twilio Dashboard' 
AUTH_TOKEN = 'You can find  on your Twilio Dashboard' 
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'
API_KEY = 'This is your Bolt Cloud accout API key'
DEVICE_ID = 'This is the ID of your Bolt device' 
mybolt = Bolt(API_KEY, DEVICE_ID)

def speak(audio): #function to make our system speak out
    engine.say(audio)
    engine.runAndWait()

def wishMe(): #wishes you, when you start based on the time
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak("Good Morning!")

    elif hour>=12 and hour<18:
        speak("Good Afternoon!")   

    else:
        speak("Good Evening!")  

    speak("I am your P A. Please tell me how may I help you")       

def takeCommand():#function to take your command and recognise it
    r = sr.Recognizer()
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source)
        print("Listening...")
        speak('Listening..')
        r.pause_threshold = 0.5
        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("Say that again please...")
        #speak("couldn't recognize")
        return "None"
    return query

def browse(comm): # to browse the website 
    webbrowser.open(comm+".com")
    
# send the message to the verified contact numbers
def msg():
    try:
        sms = Sms(SID, AUTH_TOKEN, TO_NUMBER, FROM_NUMBER)
        speak('What is the content of message')
        content=takeCommand()
        while content=="None":
            speak("Please repeat")
            content=takeCommand()
        response = sms.send_sms(content)
        print("Response received from Twilio is: " + str(response))
        print("Status of SMS at Twilio is :" + str(response.status))
        speak('message sent')
    except Exception as e:
        print(e)
        speak("Sorry boss. I am not able to send this message")

def mail():# to send emails to verified mail ids
    try:       
        mailer = Email(MAILGUN_API_KEY, SANDBOX_URL, SENDER_EMAIL, RECIPIENT_EMAIL)
        speak('What is the content of message')
        content=takeCommand()
        while content=="None":
            speak("Please repeat")
            content=takeCommand()
        response = mailer.send_email('This is mini',content)
        response_text = json.loads(response.text)
        speak("Response received from Mailgun is: " + str(response_text['message']))
        #speak('Email sent')
    except Exception as e:
        print(e)
        speak("Sorry boss. I am not able to send this Email")

def greet(query):
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak("Good Morning!")

    elif hour>=12 and hour<17:
        speak("Good Afternoon!")   
    else:
        speak("Good Evening!")
    speak(query)
    speak("How are you")
    #speak("I am damn, tell me how can I help you")

def wiki(query):#function for wikipedia search
    try:
        speak('Searching Wikipedia...')
        results = wikipedia.summary(query, sentences=2)
        speak("According to Wikipedia")
        print(results)
        speak(results)
    except Exception as e:
        speak("Coludn't search it")

if __name__ == "__main__":
    wishMe()
    while True:
        query = takeCommand().lower()
        if 'wiki' in query: #XXXX wikipedia
            query = query.replace("wiki", "")  
            wiki(query)
        elif 'greet' in query:
            query=query.replace("greet","")
            greet(query)
        elif 'hello' in query:
            print("Hello!")
            speak('Hello, Tell me how can I help you')
        elif 'how are you' in query:
            speak('I am good How can I help you')
        elif '.com' in query:#open google.com
            query = query.replace("open", "")
            browse(query)
        elif ' turn on' in query:#home automation
            mybolt.digitalWrite(0,'HIGH')
        elif 'turn off' in query:#turon off light
            mybolt.digitalWrite(0, 'LOW')           
        elif 'send message' in query:#send message to me(send message to megana)
            msg()            
        elif 'send email' in query:#send email to me(send email to megana)
            mail()
        elif 'the time' in query:   # what is the time # tell me the time
            strTime = datetime.datetime.now().strftime("%H:%M:%S")    
            speak("Sir, the time is {strTime}")            
        elif 'open file' in query:#open file
            path ='file location'
            os.startfile(path)            
        elif 'quit' in query:
            print("quiting..! Thank you for your time")
            speak("quiting..! Thank you for your time")
            break
        elif 'shutdown' in query:
            speak('Do you really want to shutdown')
            reply=takeCommand()
            if 'yes' in reply:
                os.system('shutdown /s /t 1')
            else:
                continue
        elif 'restart' in query:
            speak('Do you really want to restart')
            reply=takeCommand()
            if 'yes' in reply:
                os.system('shutdown /r /t 1')
            else:
                continue  
        else 'none' in query:
            print('repeat')

Credits

Akhila

Akhila

1 project • 3 followers
Thanks to Vinayak Shantaram Joshi.

Comments