• Latest
  • Trending
How to create your AI Virtual Assistant using Python

How to create your AI Virtual Assistant using Python

February 9, 2022
Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023
Vice President Dr. Bawumia inaugurates  ICT Hub

Vice President Dr. Bawumia inaugurates ICT Hub

April 2, 2023
Co-Creation Hub’s edtech accelerator puts $15M towards African startups

Co-Creation Hub’s edtech accelerator puts $15M towards African startups

February 20, 2023
Data Leak Hits Thousands of NHS Workers

Data Leak Hits Thousands of NHS Workers

February 20, 2023
EU Cybersecurity Agency Warns Against Chinese APTs

EU Cybersecurity Agency Warns Against Chinese APTs

February 20, 2023
How Your Storage System Will Still Be Viable in 5 Years’ Time?

How Your Storage System Will Still Be Viable in 5 Years’ Time?

February 20, 2023
The Broken Promises From Cybersecurity Vendors

Cloud Infrastructure Used By WIP26 For Espionage Attacks on Telcos

February 20, 2023
Instagram and Facebook to get paid-for verification

Instagram and Facebook to get paid-for verification

February 20, 2023
YouTube CEO Susan Wojcicki steps down after nine years

YouTube CEO Susan Wojcicki steps down after nine years

February 20, 2023
Inaugural AfCFTA Conference on Women and Youth in Trade

Inaugural AfCFTA Conference on Women and Youth in Trade

September 6, 2022
  • Consumer Watch
  • Kids Page
  • Directory
  • Events
  • Reviews
Friday, 17 July, 2026
  • Login
itechnewsonline.com
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion
Subscription
Advertise
No Result
View All Result
itechnewsonline.com
No Result
View All Result

How to create your AI Virtual Assistant using Python

by ITECHNEWS
February 9, 2022
in Data Science, Leading Stories
0 0
0
How to create your AI Virtual Assistant using Python

Introduction

A virtual assistant, also called an AI assistant or digital assistant, is an application program that understands natural language voice commands and completes tasks for the user.

We all know what is Virtual Assistant. If you don’t, don’t worry, open your mobile and say “Ok Google” or “Hey Siri”. Well, Google Assistant, Siri, Alexa all these are example of Virtual Assistant.

Content-

  1. What we are building-
  2. Code Explanation
  3. Complete code
  4. GitHub Repository
  5. How you can contribute
  6. References

 

1. What we are building-

Our virtual assistant will able to do the followings things-

YOU MAY ALSO LIKE

French Telco Orange Hit by Cyber-Attack

ATC Ghana supports Girls-In-ICT Program

Weather forecasting, Launch Games, Launch Windows Applications, Open Websites, tells you about almost everything you ask, tells you date and time, greetings, news, etc.

You can interact with your laptop’s microphone/console. The response generated by the assistant will display on the console or as a speech via the speaker.

Future Updates: Selfie Click, Chat more like humans, etc. You tell me what do you want. Or contribute in https://pypi.org/project/JarvisAI

2. Code Explanation-

So let’s create our own virtual assistant.

Notes-

  • All the codes is available on my GitHub.
  • Demo YouTube video and code YouTube video is also available on my channel.
  • Required links and packages are mentioned below.
  • Sharing would be appreciated.

Lets code-

2.1. Required packages and libraries-

pip install JarvisAI

This is the latest virtual assistant module, created by me. It provides the basic functionality of any virtual assistant. The prerequisite is only Python (> 3.6).

Usage and Features-

After installing the library you can import the module-

import JarvisAI
obj = JarvisAI.JarvisAssistant()
response = obj.mic_input()
print(response)

The functionality is cleared by the methods name. You can check the code for example.

  1. mic_input
  2. text2speech
  3. shutdown
  4. website_opener
  5. send_mail
  6. tell_me_date
  7. tell_me_time
  8. launch_any_app
  9. weather
  10. news
  11. tell_me

Read more about it here and you can also contribute to this repo here.

2.2. Code-

Imports-

import JarvisAI
import re
import pprint
import random

Object creation of JarvisAI as per as documentation–

obj = JarvisAI.JarvisAssistant()

We have created this ‘t2s(text)’ function. This will convert any text to speech. The entire program we will use (call) this function to produce speech from text.

def t2s(text):
    obj.text2speech(text)

We want to continuously listen to input from the user, so this ‘mic_input()’ will try to fetch audio from the computer’s microphone continuously. It will process the audio and return text in ‘res’ variable. We can use this ‘res’ variable to perform some action according to user input.

while True:
    res = obj.mic_input()

Weather Forecast: We are using a regular expression to match queries in user input. If ‘weather’ or ‘temperature’ is found in user input ‘res’ then we want to do weather forecasting. No need to write things from scratch, just call ‘obj.weather(city=city)’.

You just need to fetch the city from user input and pass it to the weather function. It will tell you the weather forecasting for your city.

We can pass this returned ‘weather_res’ to ‘ t2s(weather_res)’ to produce speech from ‘weather_res’ string.

while True:
    res = obj.mic_input()

if re.search('weather|temperature', res):
        city = res.split(' ')[-1]
        weather_res = obj.weather(city=city)
        print(weather_res)
        t2s(weather_res)

News: Similarly as above, match the ‘news’ word from user input ‘res’. If matched then call ‘obj.news’.

It will return 15 news as a list of strings. So, we can fetch news as ‘news_res[0]’ and pass it to ‘t2s(news_res[0])’.

while True:
    res = obj.mic_input()

if re.search('news', res):
        news_res = obj.news()
        pprint.pprint(news_res)
        t2s(f"I have found {len(news_res)} news. You can read it. Let me tell you first 2 of them")
        t2s(news_res[0])
        t2s(news_res[1])

Tells about almost everything: It will fetch the first 500 characters from Wikipedia and return them as a string. You can use ‘obj.tell_me(topic)’.

You need to pass ‘topic’ to ‘tell_me(topic=topic)’. The topic is the keyword you want to know about.

while True:
    res = obj.mic_input()

if re.search('tell me about', res):
        topic = res.split(' ')[-1]
        wiki_res = obj.tell_me(topic)
        print(wiki_res)
        t2s(wiki_res)

Date and Time: It will tell you the current date and time of your system.

while True:
    res = obj.mic_input()

if re.search('date', res):
        date = obj.tell_me_date()
        print(date)
        print(t2s(date))

if re.search('time', res):
        time = obj.tell_me_time()
        print(time)
        t2s(time)

Open Any Website: This ‘obj.website_opener(domain)’ will open any website for you. You just need to fetch the domain from user input then pass to ‘obj.website_opener(domain)’. It will open the website in your default browser.

while True:
    res = obj.mic_input()

if re.search('open', res):
        domain = res.split(' ')[-1]
        open_result = obj.website_opener(domain)
        print(open_result)

Launch any Applications, Games, etc:

This is little tricky, in ‘obj.launch_any_app(path_of_app=path)’ the function you need to pass the path of your ‘.exe’ file.

So we have created ‘dict_app’ dictionary which is having an ‘app name’ as key and ‘path’ as value. We can use this ‘dict_app’ for lookup. If the user input app exists in the dictionary then we will open it by fetching the path.

The below example is only for Chrome and Epic Games.

while True:
    res = obj.mic_input()

if re.search('launch', res):
        dict_app = {
            'chrome': 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',
            'epic games': 'C:\Program Files (x86)\Epic Games\Launcher\Portal\Binaries\Win32\EpicGamesLauncher.exe'
        }

        app = res.split(' ', 1)[1]
        path = dict_app.get(app)
if path is None:
            t2s('Application path not found')
            print('Application path not found')
else:
            t2s('Launching: ' + app)
            obj.launch_any_app(path_of_app=path)

Greetings and Chat, you can create greetings and chat like this for now.

I am working on https://pypi.org/project/JarvisAI/ to add chat kind of functionality using Tensorflow. You can contribute to making it better.

while True:
    res = obj.mic_input()

if re.search('hello', res):
        print('Hi')
        t2s('Hi')

if re.search('how are you', res):
        li = ['good', 'fine', 'great']
        response = random.choice(li)
        print(f"I am {response}")
        t2s(f"I am {response}")

if re.search('your name|who are you', res):
        print("My name is Jarvis, I am your personal assistant")
        t2s("My name is Jarvis, I am your personal assistant")

Ask- ‘What can you do?’: Here simply we are using ‘obj.t2s()’to produce some speech. If you know python, you will easily understand the code below-

while True:
    res = obj.mic_input()

if re.search('what can you do', res):
        li_commands = {
            "open websites": "Example: 'open youtube.com",
            "time": "Example: 'what time it is?'",
            "date": "Example: 'what date it is?'",
            "launch applications": "Example: 'launch chrome'",
            "tell me": "Example: 'tell me about India'",
            "weather": "Example: 'what weather/temperature in Mumbai?'",
            "news": "Example: 'news for today' ",
        }
        ans = """I can do lots of things, for example you can ask me time, date, weather in your city,
        I can open websites for you, launch application and more. See the list of commands-"""
        print(ans)
        pprint.pprint(li_commands)
        t2s(ans)

 

3. Complete code-

import JarvisAI
import re
import pprint
import random

obj = JarvisAI.JarvisAssistant()


def t2s(text):
    obj.text2speech(text)


while True:
    res = obj.mic_input()

    if re.search('weather|temperature', res):
        city = res.split(' ')[-1]
        weather_res = obj.weather(city=city)
        print(weather_res)
        t2s(weather_res)

    if re.search('news', res):
        news_res = obj.news()
        pprint.pprint(news_res)
        t2s(f"I have found {len(news_res)} news. You can read it. Let me tell you first 2 of them")
        t2s(news_res[0])
        t2s(news_res[1])

    if re.search('tell me about', res):
        topic = res.split(' ')[-1]
        wiki_res = obj.tell_me(topic)
        print(wiki_res)
        t2s(wiki_res)

    if re.search('date', res):
        date = obj.tell_me_date()
        print(date)
        print(t2s(date))

    if re.search('time', res):
        time = obj.tell_me_time()
        print(time)
        t2s(time)

    if re.search('open', res):
        domain = res.split(' ')[-1]
        open_result = obj.website_opener(domain)
        print(open_result)

    if re.search('launch', res):
        dict_app = {
            'chrome': 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',
            'epic games': 'C:\Program Files (x86)\Epic Games\Launcher\Portal\Binaries\Win32\EpicGamesLauncher.exe'
        }

        app = res.split(' ', 1)[1]
        path = dict_app.get(app)
        if path is None:
            t2s('Application path not found')
            print('Application path not found')
        else:
            t2s('Launching: ' + app)
            obj.launch_any_app(path_of_app=path)

    if re.search('hello', res):
        print('Hi')
        t2s('Hi')

    if re.search('how are you', res):
        li = ['good', 'fine', 'great']
        response = random.choice(li)
        print(f"I am {response}")
        t2s(f"I am {response}")

    if re.search('your name|who are you', res):
        print("My name is Jarvis, I am your personal assistant")
        t2s("My name is Jarvis, I am your personal assistant")

    if re.search('what can you do', res):
        li_commands = {
            "open websites": "Example: 'open youtube.com",
            "time": "Example: 'what time it is?'",
            "date": "Example: 'what date it is?'",
            "launch applications": "Example: 'launch chrome'",
            "tell me": "Example: 'tell me about India'",
            "weather": "Example: 'what weather/temperature in Mumbai?'",
            "news": "Example: 'news for today' ",
        }
        ans = """I can do lots of things, for example you can ask me time, date, weather in your city,
        I can open websites for you, launch application and more. See the list of commands-"""
        print(ans)
        pprint.pprint(li_commands)
        t2s(ans)

You can feel free to use my code. Star it if you like my work, subscribe on YouTube if you love.

Just clone the repository- https://github.com/Dipeshpal/Jarvis-Assisant.git

Then run pip install -r requirements.txt

It will automatically install everything.

4. Github Repository

Source: Dipesh Pal Data Scientist at Calsoft Pvt. Ltd
Tags: AI Virtual Assistant using Python
ShareTweet

Get real time update about this post categories directly on your device, subscribe now.

Unsubscribe

Search

No Result
View All Result

Recent News

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023

About What We Do

itechnewsonline.com

We bring you the best Premium Tech News.

Recent News With Image

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025

Recent News

  • Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa July 29, 2025
  • French Telco Orange Hit by Cyber-Attack July 29, 2025
  • ATC Ghana supports Girls-In-ICT Program April 25, 2023
  • Vice President Dr. Bawumia inaugurates ICT Hub April 2, 2023
  • Home
  • InfoSec
  • Opinion
  • Africa Tech
  • Data Storage

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
Go to mobile version