Top Ad unit 728 × 90

Voice Assistants using python

Voice Assistant:

Voice assistants

Looking at the market majorly, we realize voice assistants are all up to take over our tasks. Alexa and ok google etc. are already leading the market. How about you have a private assistant of your own.

Python as well as know, an best language for beginner , scriptwriters  and developers. Let's create a script for Voice Assistant using python language. The assistant can be manipulated according to the user's needs. 


Classes and Objects in python

 

Modules Needed for this python project:

 Pyttsxs3 :- Its module is a text to speech conversion library in python language.

   Unlike alternative libraries, it work offline.


Speech Recognition :-  Speech recognition, also known as automatic speech recognition, Computer speech recognition, or speech to text, is capability which enables a program to process human speech into a written format. while it's commonly confused with voice recognition focuses on the translation of speech from a verbal format to a text one whereas voice recognition just seeks to identity an individual user's voice.


● Web browser:-  This built in module is used for web search.

● Date and Time:- Show the date and time.

● Pyjikes:- Pyjokes is a tool for collecting python more jokes online.


Source code:

import pyttsx3
import speech_recognition as sr
import webbrowser
import datetime
import pyjokes
import os
import time


def sptext():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
try:
print("recognizing...")
data = recognizer.recognize_google(audio)
print(data)
return data
except sr.UnknownValueError:
print("Not Understand")


def speechtx(x):
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
rate = engine.getProperty('rate')
engine.setProperty('rate', 120)
engine.say(x)
engine.runAndWait()


speechtx("good morning kamaljeet")
if __name__ == '__main__':

# if "computer" in sptext().lower():
while True:
data1 = sptext().lower()
if "your name" in data1:
name = "my name is kamaljeet chauhan"
speechtx(name)
elif "old are you" in data1:
age = "i am 19 year old"
speechtx(age)

elif 'time' in data1:
time = datetime.datetime.now().strftime("%I%M%p")
speechtx(time)

elif 'youtube' in data1:
webbrowser.open("https://www.youtube.com/")

elif "instagram" in data1:
webbrowser.open("https://www.instagram.com/")

elif "google" in data1:
webbrowser.open("https://www.google.com/")

elif "joke" in data1:
joke_1 = pyjokes.get_joke(language='en', category='neutral')
print(joke_1)
speechtx(joke_1)

elif "play video" in data1:
add = "C:\\Users\\Acer\\Videos"
listvideo = os.listdir(add)
print(listvideo)
os.startfile(os.path.join(add, listvideo[3]))

elif "exit" in data1:
speechtx("thank you")
break

time.sleep(8)

# else:
# print("thanks")

 


 

Voice Assistants using python Reviewed by For Learnig on June 15, 2023 Rating: 5

No comments:

If you have any doubts, please tell me know

Contact Form

Name

Email *

Message *

Powered by Blogger.