Google Assitance using Python

Sonu Gupta
1 min readApr 29, 2021

import speech_recognition as sr

#for window the engine is sapi5

#for mac or linux engine is nsss

engine = pyttsx3.init(‘espeak’)

client = wolframalpha.Client(‘Your Client Id’)

voices = engine.getProperty(‘voices’)

rate = engine.getProperty(‘rate’)

engine.setProperty(‘rate’, rate-25)

currentH = int(datetime.datetime.now().hour)

speak(‘Hello Sir, I am your digital assistant Cortana!’)

speak(‘How may I help you?’)

r.energy_threshold = 3093.7084974832646

with sr.Microphone() as source:

query = r.recognize_google(audio, language=’en-in’)

except sr.UnknownValueError:

webbrowser.open(‘www.youtube.com')

webbrowser.open(‘www.google.co.in')

webbrowser.open(‘www.gmail.com')

‘I am nice and full of energy’]

speak(random.choice(stMsgs))

speak(‘Who is the recipient? ‘)

speak(‘What should I say? ‘)

server = smtplib.SMTP(‘smtp.gmail.com’, 587)

server.login(“Your_Username”, ‘Your_Password’)

server.sendmail(‘Your_Username’, “Recipient_Username”,

speak(‘Sorry Sir! I am unable to send your message at this moment!’)

speak(‘Bye Sir, have a good day.’)

speak(‘Bye Sir, have a good day.’)

music_folder = Your_music_folder_path

music = [music1, music2, music3, music4, music5]

random_music = music_folder + random.choice(music) + ‘.mp3’

speak(‘Okay, here is your music! Enjoy!’)

res = client.query(query)

results = next(res.results).text

speak(‘WOLFRAM-ALPHA says — ‘)

results = wikipedia.summary(query, sentences=2)

speak(‘WIKIPEDIA says — ‘)

webbrowser.open(‘www.google.com')

speak(‘Next Command! Sir!’)

Originally published at https://www.pythonclasses.online.

--

--

Sonu Gupta

I am a Python developer specialised in Machine Learning Data Science and backend development for complex scalable web apps using Django.