BOB = A python voice assistant 


Table of Content

  1. What is a voice assistant ?
  2. History of voice assistants
  3. Pros and cons of a voice assistant
  4. Obstacles overcame by BOB
  5. Creating a voice assistant
  6. Code Implementation
  7. Conclusion


What is a voice assistant ?

A voice assistant is a computer assistant that listens to particular vocal commands and returns relevant information or performs specified actions as desired by the user. Voice assistants recognize vocals using speech recognition, language processing algorithms, and voice synthesis.


Voice assistants can return relevant information based on particular commands and keywords used by the user. While voice assistants can be entirely software-based and integrated with a wide range of devices, some are designed only for a specific device application or use.


Nowadays, voice assistants are a part of many devices like smartphones, smart TVs, computers, speakers, etc., because voice assistants can handle almost any situation at hand.


History of voice assistants

Voice assistants have a long history that dates back over a century, but apps such as Siri have only been released within the past ten years.


Radio Rex-the first voice-activated machine which was released in the year of 1922. Radio Rex was a toy with a dog inside the house, which Elmwood Button Co invented. He named the dog Rex. The dog inside the house is controlled by the spring connected to an electromagnet. The magnet was sensitive to an energy of more than 500Hz. Thus, the words 'Rex' trigger the magnet and propels the dog out of the house.


Later in 1952, an 'automatic digit recognizer' was introduced by Bell Labs, which used to recognize 0-9 numbers. Extension to this in 1962, IBM began its journey in voice assistant by introducing its first voice assistant product, 'shoebox'. Shoebox can recognize the numbers 0-9 and performs six basic mathematic operations like addition, subtraction, etc., and in 1994, IBM created history by creating the first smart voice assistant -' Simon by IBM'.

This journey of smart voice assistants continued with 'google voice assistant' in 2008, 'Siri' in 2010, 'IBM Watson' in 2011, and 'Amazon Alexa' in 2015.



Pros and cons of a voice assistant.

Voice Assistants from corporate giants like Google Assistant, Siri, and Alexa are the major examples. Here are some of the Pros and cons of voice assistants.



Helps in saving your Time

It can act as an extra pair of hands for you and save you a lot of time. You may communicate with Google Maps while driving and ask for directions to your desired location. You'll be less likely to get lost as a result of this. In addition, it saves you the trouble of having to pull out your phone and look up the directions on the map.


Assist in phone operation tasks

Voice assistants can automate many of the time-consuming tasks associated with phone operations, allowing your personnel to focus on more important tasks. They are capable of handling incoming calls as well as SMS text messaging. It can also forward your calls to a different phone number.

You can tell them to take notes because it can convert your spoken words into text, that Output can write into a document. It also can set alarms and reminders. 


Can get things done fast

Talking is faster than typing. We can ask our voice assistant to draft and send a message instead of writing or typing a message. Moreover, it takes less time to provide a voice command than it does to travel to another area in the house to finish a task. So, for example, it's easier to tell Google to turn up the light than to get out of bed and do it yourself. As technology becomes more integrated into more devices, it makes life easier. 



Signal Strength

Digital voice assistants are limited to places with a high-speed network, which is one of its drawbacks. You'll have a hard time keeping them alive if you don't have access to the 4G network. 

You must ensure that your network is quick if you want the greatest results from your voice assistant. Unfortunately, this means that most people living in rural areas or remote locations will not get the most out of them. 


Privacy Concerns

Manufacturers can track users' data. Theft of personal data can affect a person in many ways. For example, there have been complaints about data theft by manufacturers using voice assistance. However, many companies were working and offering better privacy tools for users.


Obstacles overcame by BOB

Usually, a voice assistant can do numerous tasks. But there are certain limitations for them. For example, No voice assistant can go to your database or data set and give you the required data. If we ask Siri what my college attendance in the last semester is? Siri probably can't answer. But BOB can do it if we provide the data set whenever bob is asked who is the topper of the branch, who has the least attendance, least marks in a particular subject, etc. Then, BOB will answer the questions. It can also do some general tasks like other voice assistants do. We can customize the command and the results for the command. 


Creating a voice assistant

For creating a voice assistant using python, we need to install and import some libraries which play a crucial role in the execution. We are going to use Python version 3.7. There are many updated versions, but some of the libraries we are using don't support the versions above 3.7.




Install libraries using the below commands in the Pycharm terminal or Conda or Use Navigator


Python audio

We use the PyAudio library to start with audio playback and recording in a Python environment on Windows, Linux, and macOS. 


    # Install using conda or navigator
    # pip install PyAudio

Python text to speech

pyttsx3 is a Python-based text-to-speech conversion library.

It can convert text to speech without the internet and is compatible with Python 2 and Python 3. 

    # pip install pyttsx3


Pandas is data manipulation and analysis library for the Python programming language. We use pandas to load data and filter data.

    # pip install pandas


Python what kit can be used to google search, play songs on youtube, and convert text to handwritten. We use this library to play videos on youtube.

    # pip install pywhatkit

Code Implementation

    # Importing the Necessary Libraries
    import speech_recognition as sr
    import pyttsx3
    import pandas as pd
    import os
    import pywhatkit
    import datetime
    import wikipedia

Reading the data 

    # Importing csv using pandas
    # Download this data file used in next line by clicking here.
    df = pd.read_csv("O16CSE.csv")

    # Filling serial number with empty space
    df.set_index([[''] * len(df)], inplace=True)

    # Initializing the speech recognizer and text to speech converter
    listner = sr.Recognizer()
    engine = pyttsx3.init()
    #setting voice speed rate
    engine.setProperty("rate", 120)

    # Using device microphone as a source speech recognizer takes input
    run = True
    while run:
        with sr.Microphone() as source:
            engine.say('please speak with me now')
            voice = listner.listen(source)

            # The vocal input which was given will convert as possible test outcomes by google analyzer.
            command = listner.recognize_google(voice)
            command = command.lower()
            pd.set_option("display.max_rows", None, "display.max_columns", None)

            # if the text outcome is equal to the string used in the condition task will be executed
            if 'what is your name' in command:
                engine.say('my name is bobb. ')
            # If we want to speak to bob we should use trigger word 'bob' otherwise he wont repond to the command
            elif 'bob'  in command:
                engine.say('things you spoke to me is..')
                if 'who are you' in command:
                    engine.say('i am your personalised voice assistant ')
                # asking bob to shutdown the system
                elif 'shut down' in command:
                    os.system("shutdown /s /t 1")
                elif 'restart' in command:
                    os.system("shutdown /r /t 1")
                elif 'logout' in command:
                    os.system("shutdown -l")
                            # if we want bob to play song from youtube
                elif 'play' in command:
                    command = command.replace('bob play', "")
                    engine.say('playing' + command)
                # will let you know the time
                elif 'time' in command:
                    time ='%I:%M %p')
                # will give information from wikipedia
                elif 'info' in command:
                    command = command.replace('bob give me info about', "")
                    info = wikipedia.summary(command, 5)
                # projecting filtered student data from csv
                elif 'student profile' in command:
                    command = command.replace('bob give me the student profile ', "")
                    command = command.replace('', "")
                    command = int(command)
                    df1 = df[(df['ID'] == command)]
                    engine.say('student details')
                    df2 = df1[['NAME']]
                    df3 = df1[['BRANCH']]
                    df4 = df1[['ATTENDANCE ']]
                elif 'topper' in command:
                    a = df['TOTAL']
                    topper = a.max()
                    df1 = df[(df['TOTAL'] == topper)]
                    print(df1[['ID', 'NAME', 'TOTAL']])
                    engine.say('ID', 'student details')
                    df2 = df1[['NAME', 'TOTAL']]
                elif 'least attendance' in command:
                    a = df['ATTENDANCE ']
                    L_A = a.min()
                    df1 = df[(df['ATTENDANCE '] == L_A)]
                    print(df1[['ID', 'NAME', 'BRANCH', 'ATTENDANCE ']])
                    df2 = df1[['ID', 'NAME', 'BRANCH', 'ATTENDANCE ']]
                elif 'subject' in command:
                    if  'least' in command:
                        if 'software engineering' in command:
                            a = df['SE']
                            ff = a.min()
                            df1 = df[(df['SE'] == ff)]
                            print(df1[['ID' , 'NAME', 'SE']])
                            df2 = df1[['ID', 'NAME', 'SE']]
                        elif 'computer netwroks' in command:
                            a = df['CN']
                            ff = a.min()
                            df1 = df[(df['CN'] == ff)]
                            print(df1[['ID', 'NAME', 'CN' ]])
                            df2 = df1[['ID', 'NAME', 'CN']]
                        elif 'database management system' in command:
                            a = df['DBMS']
                            ff = a.min()
                            df1 = df[(df['DBMS'] == ff)]
                            print(df1[['ID', 'NAME', 'DBMS']])
                            df2 = df1[['ID', 'NAME', 'DBMS']]
                    elif 'top' in command:
                        if 'software engineering' in command:
                            a = df['SE']
                            ff = a.max()
                            df1 = df[(df['SE'] == ff)]
                            print(df1[['ID', 'NAME', 'SE']])
                            df2 = df1[['ID', 'NAME', 'SE']]
                        elif 'computer netwroks' in command:
                            a = df['CN']
                            ff = a.max()
                            df1 = df[(df['CN'] == ff)]
                            print(df1[['ID', 'NAME', 'CN']])
                            df2 = df1[['ID', 'NAME', 'CN']]
                        elif 'database management system' in command:
                            a = df['DBMS']
                            ff = a.max()
                            df1 = df[(df['DBMS'] == ff)]
                            print(df1[['ID', 'NAME', 'CN']])
                            df2 = df1[['ID', 'NAME', 'CN']]
               # if user wants to exit and user dont respond it automatically exits.
        if command == ''or command=='bob exit':
                run = False
    engine.say('thank you')


In this project, we used python 3.7 and some python libraries in the pycharm environment to create and execute the voice assistant. The complete voice assistant works on trigger words. Whenever the user gives the vocal input, input will be converted to text, and the converted text will be passed through various conditions. When the condition satisfies, the respective task will be executed. Follow the user manual to use this voice assistant. You can also check this simple implementation of audio data management in Python to create a audio book.




About the Author's:

Sujith kumar

Sujith Kumar

Sujith Kumar is a Data Science intern at simple and real Analytics. He is a self-learning data science aspirant. Pursuing  graduation bachelors in computer science and engineering at IIIT-RGUKT.


Mohan Rai

Mohan Rai is an Alumni of IIM Bangalore , he has completed his MBA from University of Pune and Bachelor of Science (Statistics) from University of Pune. He is a Certified Data Scientist by EMC. Mohan is a learner and has been enriching his experience throughout his career by exposing himself to several opportunities in the capacity of an Advisor, Consultant and a Business Owner. He has more than 18 years’ experience in the field of Analytics and has worked as an Analytics SME on domains ranging from IT, Banking, Construction, Real Estate, Automobile, Component Manufacturing and Retail. His functional scope covers areas including Training, Research, Sales, Market Research, Sales Planning, and Market Strategy.