Step by Step Procedure to create PDF Speaker using Python
Hello friends how are you, Today in this post "PDF Speaker using Python" i am going to teach you how you can create a PdfSpeaker. I think it is something interesting for everyone because you have heard PdfReader but today i will teach using 8 lines of code to create PdfSpeaker. Here in this project upload any PDF file pass the page number and it will speak to you like a story telling, can't believe? just go through this post you will get something new today.
If you are a computer science students or teacher and want to learn something interesting in programming then just go through this post. This can also be a simple and interesting project for you.
We know that PDF[Portable Document File] file is the most used digital media file which is used to store many useful information for example subject notes, project reports , business related data, personal information etc. Whenever we need that data we open the file and we read that file but today i am going to present something new in which you can listen what you have stored into it. It is also said that the thing like story , song etc which we listen we can remember for long time
Now i am going to explain it step by step so just go through this post to understand this completely.
If you want to understand this through video then watch this video i have explained it step by step live
Step 1: Install Python : Click here to watch a video on how to install python or Open any browser and type Download Python and click the first link you will get official website of python here you will get a Download button and after clicking on this button you will get exe of latest python version just install it into your system.
Step 2: Install Pycharm | Create Project | Install Library: Click here to watch a single video on How to install Pycharm | Create Project | Install Library or To install Pycharm IDE Open any browser and type Download Pycharm and click the first link you will get official website of Pycharm here you will get a black download button and after clicking on this button you will get an exe of Pycharm , just install it into your system. If you are facing problem to install then watch the above video i have explained step by step.
Step 3: Create Project : Open Pycharm click on File which is in top left of screen and select New Project. Then you will get a screen. Here first you need to select directory of your project and then type a name for your project like "PdfSpeaker" after directory name, and at last click the create button to create this project.
Step 4: Create Python file: To create a python file for coding in your project just right click on project name "PdfSpeaker" and select new and click on Python File , you will get popup screen in which you have to type a name like "Program" for python file and press enter, it will create a python file with name Program.py inside the project PdfSpeaker.
Line 1: import library: Here in this we will import the needed library
#import libraries import pyttsx3,PyPDF2 #open open file #Note: mypdf.pdf should be stored into project folder pdfFile=open("mypdf.pdf",'rb') #Read pdf file pdfReader=PyPDF2.PdfFileReader(pdfFile) #initialize speaker speaker=pyttsx3.init() #get particular page #here 0 means page number 1 page=pdfReader.getPage(0) #extract text of page text=page.extractText() #speech the text speaker.say(text) #make speech audible speaker.runAndWait()
from tkinter import* from tkinter import filedialog def convert(): # import libraries import pyttsx3, PyPDF2 # open open file # Note: mypdf.pdf should be stored into project folder pdfFile = open(fname, 'rb') # Read pdf file pdfReader = PyPDF2.PdfFileReader(pdfFile) # initialize speaker speaker = pyttsx3.init() # get particular page # here 0 means page number 1 page = pdfReader.getPage(0) # extract text of page text = page.extractText() # speech the text speaker.say(text) # make speech audible speaker.runAndWait() def UploadAction(): #uploading file filename = filedialog.askopenfilename(filetypes =[('Text Files', '*.pdf')]) #showing message for uploaded file msgForUpload.set("Uploaded:"+filename) #declaring global variable global fname #passing uploaded filename into fname fname=filename root =Tk() #setting window height and width root.geometry("600x200") #setting window background color root["bg"]="#424B4C" #setting title of window root.title("Krazy:PdfSpeaker") #creating variable for messages global msgForUpload global msgForGenerate msgForUpload=StringVar() msgForGenerate=StringVar() #label for uploading message Label(root,text="",textvariable=msgForUpload,font="Arial 12",bg="#424B4C",fg="white").place(x=80,y=30) #button for upload file Button(root, text='Open', command=UploadAction,font="Arial 12 bold",width="10",bg="#0E2E1E",fg="white").place(x=80,y=70) #button for convert Button(root,text="Play",font="Arial 12 bold",width="10",command=convert,bg="#0E2E1E",fg="white").place(x=350,y=70) #label for generated/success message Label(root,text="",textvariable=msgForGenerate,font="Arial 12",bg="#424B4C",fg="white").place(x=80,y=120) root.mainloop()
0 Comments