0% found this document useful (0 votes)
41 views4 pages

Jarvis

The document is a Python script that utilizes the pyttsx3 and speech_recognition libraries to create a voice assistant. It initializes a text-to-speech engine, greets the user based on the time of day, and listens for voice commands. The script captures audio input, recognizes it using Google's speech recognition, and handles exceptions if recognition fails.

Uploaded by

sdxltanmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views4 pages

Jarvis

The document is a Python script that utilizes the pyttsx3 and speech_recognition libraries to create a voice assistant. It initializes a text-to-speech engine, greets the user based on the time of day, and listens for voice commands. The script captures audio input, recognizes it using Google's speech recognition, and handles exceptions if recognition fails.

Uploaded by

sdxltanmay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

from threading import main_thread

from pip import main


import pyttsx3
import speech_recognition as sr
import datetime
import pyaudio

engine = pyttsx3.init('sapi5')
voices
=engine.getProperty('voices')
#print(voices[0].id)
engine.setProperty('voice',voices
[1].id)

def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishme():

hour=int(datetime.datetime.now().
hour)
if hour>=0 and hour<12:
speak("Good Morning!")
elif hour >=12 and hour<18:
speak("Good afternoon")
else:
speak("Good evening!")
speak("I am your assistant
saaar How may i help you? ")

def takeCommand():

r =sr.Recognizer()
with sr.Microphone() as
source :
print("Listening...")
r.pause_threshold =1
r.energy_threshold=4000
audio=r.listen(source)

try :
print("Recognizing...")

query=r.recognize_google(audio,La
nguage='en-in')
print(f"User said
{query}\n")
except Exception as e:
# print(e)

print("Say that again


please...")
return "None"
return query

if __name__ == '__main__':

speak("...")
wishme()
takeCommand()

You might also like