Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added AI for Gather information #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions AIforPdfReader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import pyttsx3 #pip install pyttsx3
import speech_recognition as sr #pip install speechRecognition
import datetime
import wikipedia #pip install wikipedia
import webbrowser
import PyPDF2
import tkinter as tk
from tkinter import Variable, filedialog

# import pyaudio
root = tk.Tk()
root.withdraw()

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


# def file():
# # path of the PDF file
# path = filedialog.askopenfilename()
# print(path)

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


def wishMe():
speak("Please Enter Your Name:- ")
print("Enter Here:- ")
name = input("")
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning! {}".format(name))

elif hour>=12 and hour<18:
speak("Good Afternoon! {}".format(name))

else:
speak("Good Evening! {}".format(name))

speak("I am Turtle. Please tell me how may I help you")

def pdfspeak():
# speak("Please Select Your File ")
path = filedialog.askopenfilename()
print(path)
# creating a PdfFileReader object
pdfReader = PyPDF2.PdfFileReader(path)

# the page with which you want to start
# this will read the page of 25th page.
from_page = pdfReader.getPage(0)

# extracting the text from the PDF
text = from_page.extractText()
engine = pyttsx3.init('sapi5')
# reading the text
voices = engine.getProperty('voices')
# print(voices[1].id)
engine.setProperty('voice', voices[1].id)
speak = pyttsx3.init()
speak.say(text)
speak.runAndWait()

def takeCommand():
#It takes microphone input from the user and returns string output

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

try:
print("Recognizing...")
query = r.recognize_google(audio, language='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__":
wishMe()
while True:
query = takeCommand().lower()
if 'wikipedia' in query:
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak("According to Wikipedia")
print(results)
speak(results)

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

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

elif 'the time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Sir, the time is {strTime}")

elif 'play book' in query:
speak("Playing Your Book. Please Select book file to Play")
pdfspeak()

elif 'play pdf' in query:
speak("Playing Your Pdf. Please Select Pdf file to Play")
pdfspeak()

elif 'play story' or 'tell story' in query:
speak("Playing Your Story. Please Select Story file to Play")
pdfspeak()