Coders Packet

Create a virtual voice assistant in Python

By Siddhant prabhakar

Create virtual voice assistant in Python using Pycharm or VS code. import pyttsx3, Wikipedia, speechRecognition, pyaudio modules from the terminal in Pycharm or VS code.

import pyttsx3 modules, Pyaudio from terminal. If microphone faces problem in code use k.adjust_for_ambient_noise(source,duration=1) for noise cancellation in def inter

import speech_recognition as bt
import pyttsx3
import os
import webbrowser
import wikipedia
import datetime
import smtplib

e = pyttsx3.init('sapi5')
v = e.getProperty('voices')
e.setProperty('voice', v[0].id)


def bolo(audio):
    e.say(audio)
    e.runAndWait()


def siddhant():
    g = int(datetime.datetime.now().hour)
    if g>=12 and g<18:
        bolo("Namaste")

    elif g>=0 and g<12:
        bolo("raam raam")

    else:
        bolo("hello sir...")

    bolo("my name is allexa.  can you please tell me how could I serve you")

def inter():


    k = bt.Recognizer()
    with bt.Microphone() as h:
        print("  sidhant bro i am trying to Listen...")
        k.adjust_for_ambient_noise(h,duration=1)
        k.pause_threshold = 1
        audio = k.listen(h)

    try:
        print("kaam kr rha hoo....")
        q = k.recognize_google(audio, language='en-in')
        print(f"User said: {q}\n")

    except Exception as m:

        print("phir se bolo...")
        return "None"
    return q


if __name__ == "__main__":
    siddhant()
    while True:

        q = inter().lower()


        if 'wikipedia' in q:
            bolo('Searching results...')
            q = q.replace("wikipedia", "")
            x = wikipedia.summary(q, sentences=2)
            bolo("According to results")
            print(x)
            bolo(x)

        elif 'open youtube' in q:
            webbrowser.open("youtube.com")

        elif 'open google' in q:
            webbrowser.open("google.com")











 

Download project

Reviews Report

Submitted by Siddhant prabhakar (siddhant142)

Download packets of source code on Coders Packet