Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions AutomationScripts/Gwen - Voice Assistant/Gwen/Gwen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import pyttsx3 as px
import speech_recognition as sr

from browser import *
from youtube import *
from weather import *
from gmail import *
rx = px.init() # instance of init class
#it gets the info of the current driver in use
rate= rx.getProperty('rate')
rx.setProperty('rate',150)
voices=rx.getProperty('voices')
rx.setProperty('voice',voices[1].id)



def speak(text):
rx.say(text)
rx.runAndWait() #ask the computer to wait untill the sentence gets finished

r = sr.Recognizer()#instance of Recognizer class.It helps to retrive information from a source
speak('Hey I am Gwen, Your voice assistant.')
def listening():
with sr.Microphone() as source:
r.energy_threshold=10000 #increases the spectrum of voice
r.pause_threshold=1
r.adjust_for_ambient_noise(source,1.2)#cancels the noise
print("Listening....")
audio=r.listen(source)
try:
text = r.recognize_google(audio)#send the audio to google api engine which returns the text of the audio
print(text)

except Exception as e:
print(e)
speak(e)
return None
return text
def call(text):

if "Gwen" in text:
return True
return False
while True:
try:
text = listening()
if call(text):
if "Hey Gwen you there" in text:
speak('Yes Sir, At your service')
elif "Hii Gwen " in text:
speak("Hii, Paras. How are you?")

elif "what" and "about" and "you" in text:
speak("I am having a good day .")
speak("What can I do for you?")

text2=listening()


if "what will be the weather today" in text2:
speak(des())

if 'tell me about' in text2:
inf=" ".join(text2.split()[3:])
print(f"Searching {inf} in Google ")
speak(f"Searching {inf} in Google ")
assist = info()
text=assist.get_info(inf)
speak(text)

elif "how much" in text2:
x=" ".join(text2.split()[3:])
print(f"Searching {x} in Google ")
speak(f"Searching {x} in Google ")
assist=info()
text=assist.get_info(x)
speak(text)

elif "is" in text2:

print(f"Searching {text2} in Google ")
speak(f"Searching {text2} in Google ")
assist=info()
text=assist.get_info(text2)
speak(text)

elif "get me a tutorial" in text2:
tutorial=" ".join(text2.split()[5:])
print(f"Searching a tutorial for {tutorial} in Youtube")
speak(f"Searching a tutorial for {tutorial} in Youtube")

assist = music()
assist.play(tutorial)
elif "play" in text2:
song=" ".join(text2.split()[1:])

print(f"Playing {song} in Youtube")
speak(f"Playing {song} in Youtube")

assist = music()
assist.play(song)

elif "mail" in text2:
name="".join(text2.split()[4:])
speak("Email address of the "+name)

to=listening()
speak("Subject of the mail?")
sub=listening()
speak("Body of the mail")
mssg=listening()
assist=email()
txt=assist.mail(to,sub,mssg)
speak("Sending an email to "+ name)
speak(txt +name)
elif 'stop' in text2 or 'quit' in text2:
break
except:
pass
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions AutomationScripts/Gwen - Voice Assistant/Gwen/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
api = 'ca16f1af2f5c81f24e************dc'

#generate your own api
2 changes: 2 additions & 0 deletions AutomationScripts/Gwen - Voice Assistant/Gwen/api.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
api='ca16f1af2f5c8***********dc'
//get your own api
55 changes: 55 additions & 0 deletions AutomationScripts/Gwen - Voice Assistant/Gwen/browser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from selenium import webdriver

class info():
def __init__(self):
self.driver = webdriver.Chrome(r'Enter the path of your selenieum webdriver')

def get_info(self,query):
self.query = query
self.driver.get(url="https://www.google.com/")
search=self.driver.find_element_by_xpath('/html/body/div[1]/div[3]/form/div[2]/div[1]/div[1]/div/div[2]/input')
search.click()
search.send_keys(query)
enter=self.driver.find_element_by_xpath('/html/body/div[1]/div[3]/form/div[2]/div[1]/div[2]/div[2]/div[2]/center/input[1]')
enter.click()

try:
txt=self.driver.find_element_by_xpath('//*[@id="kp-wp-tab-overview"]/div[1]/div/div/div/div/div[1]/div/div/div/div/span[1]').text
return txt
except:
pass
try:
txt2=self.driver.find_element_by_xpath('//*[@id="rso"]/div[1]/div/div[1]/div/div[1]/div/div[2]/div/span[1]/span').text
return txt2
except:
pass
try:
txt3=self.driver.find_element_by_xpath('//*[@id="knowledge-currency__updatable-data-column"]/div[1]/div[2]/span[1]').text
txt4=self.driver.find_element_by_xpath('//*[@id="knowledge-currency__updatable-data-column"]/div[1]/div[2]/span[2]').text
return txt3+" "+txt4
except:
pass
try:
txt5=self.driver.find_element_by_xpath('//*[@id="rso"]/div[1]/div/div[1]/div/div[1]/div/div[1]/div/span/span').text
return txt5
except:
pass
try:
txt6=self.driver.find_element_by_xpath('//*[@id="kp-wp-tab-overview"]/div[1]/div/div[2]/div/div/div[3]/div/div/div/div/span').text
return txt6
except:
pass

try:
txt6=self.driver.find_element_by_xpath('//*[@id="kp-wp-tab-overview"]/div[2]/div/div/div/div/div[1]/div/div/div/div/span[1]').text
return txt6
except:
pass

try:
txt6=self.driver.find_element_by_xpath('//*[@id="rso"]/div[1]/div/div/div[2]/div/span/span').text
return txt6
except:
pass


29 changes: 29 additions & 0 deletions AutomationScripts/Gwen - Voice Assistant/Gwen/gmail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
class email():
def __init__(self):
self.server=smtplib.SMTP_SSL(host="smtp.gmail.com",port=465)
self.mssg = MIMEMultipart()
def mail(self,to,sub,msg):

try:
self.server.login("email@gmail.com", "password")

self.mssg['Subject']=sub
self.mssg.attach(MIMEText(msg,'plain'))
text=self.mssg.as_string()
self.server.sendmail("example@gmail.com",to,text)
self.server.quit()
return "Email sent successfully to "
except:
return "Sorry, Could Not send the mail to "









11 changes: 11 additions & 0 deletions AutomationScripts/Gwen - Voice Assistant/Gwen/weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import requests

from api import *

api_address='http://api.openweathermap.org/data/2.5/weather?q=Dehradun&appid=' + api
data=requests.get(api_address).json()

def des():
description=data['weather'][0]['description']
return description

12 changes: 12 additions & 0 deletions AutomationScripts/Gwen - Voice Assistant/Gwen/youtube.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from selenium import webdriver

class music():
def __init__(self):
self.driver = webdriver.Chrome(r"Enter the path of your selenieum webdriver")

def play(self,query):
self.query = query
self.driver.get(url = "https://www.youtube.com/results?search_query="+query)
video = self.driver.find_element_by_xpath('//*[@id="video-title"]/yt-formatted-string')
video.click()

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions AutomationScripts/Gwen - Voice Assistant/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Gwen (Voice Assistant)

<img src = "https://raw.githubusercontent.com/Paras0-7/Gwen/main/Gwen.png">

This python code snippet will give you your own voice assistant <b>Gwen.</b>
It will greet you and do tasks that you asked for. It uses selenium automation to access the web browser.<br>
It will perform tasks such as : <br>
i) Get you any sort of information and read it.<br>
ii) Play music<br>
iii) Send Emails


## To run the code --
i) First download the code <br>
ii) Open command prompt <br>
iii) Install the dependencies <br>

```
python -m pip install --upgrade pip
pip install requests
pip install pyttsx3 // this library will help to convert text to speech
pip install speech_recognition // this library will help to recognize the speech pattern
pip install pyaudio

```
iv) Install selenium webdriver for your browser </t> Get the driver for Chrome from this link </t>[ChromeDriver](https://chromedriver.chromium.org/downloads)
<br>
v) Run the application
```
python Gwen.py
```


![built with love](https://forthebadge.com/images/badges/built-with-love.svg) <br>

Checkout my GitHub Profile</t>[Paras0-7](https://github.com/Paras0-7)




5 changes: 5 additions & 0 deletions AutomationScripts/Gwen - Voice Assistant/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Packages required for this script are :
i) requests
ii) pyttsx3 // this library will help to convert text to speech
iii) speech_recognition // this library will help to recognize the speech pattern
iv ) pyaudio
1 change: 1 addition & 0 deletions AutomationScripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Automation Scripts is a collection of scripts/projects which helps us in automat
- [Weather Notifier](https://github.com/Komal-99/Awesome_Python_Scripts/tree/weather/AutomationScripts/Weather%20Notifier)
- [Grammar Correction](https://github.com/prathimacode-hub/Awesome_Python_Scripts/tree/main/AutomationScripts/Grammar%20Correction)
- [Jokes Automation](https://github.com/prathimacode-hub/Awesome_Python_Scripts/tree/main/AutomationScripts/Jokes%20Automation)