├── .idea
├── .gitignore
├── PythonPDF2Voice.iml
├── inspectionProfiles
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
└── vcs.xml
├── README.md
└── src
├── EntryTextVar.py
├── ISellMyDreams.pdf
├── PDF2Audio2PDF.py
├── pdf2speech.py
└── samplepdf.pdf
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | # Editor-based HTTP Client requests
5 | /httpRequests/
6 | # Datasource local storage ignored files
7 | /dataSources/
8 | /dataSources.local.xml
9 |
--------------------------------------------------------------------------------
/.idea/PythonPDF2Voice.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ├── .idea
2 | ├── .gitignore
3 | ├── PythonPDF2Voice.iml
4 | ├── inspectionProfiles
5 | │ └── profiles_settings.xml
6 | ├── misc.xml
7 | ├── modules.xml
8 | └── vcs.xml
9 | ├── README.md
10 | └── src
11 | ├── EntryTextVar.py
12 | ├── ISellMyDreams.pdf
13 | ├── PDF2Audio2PDF.py
14 | ├── pdf2speech.py
15 | └── samplepdf.pdf
16 |
17 |
18 | /.idea/.gitignore:
19 | --------------------------------------------------------------------------------
20 | 1 | # Default ignored files
21 | 2 | /shelf/
22 | 3 | /workspace.xml
23 | 4 | # Editor-based HTTP Client requests
24 | 5 | /httpRequests/
25 | 6 | # Datasource local storage ignored files
26 | 7 | /dataSources/
27 | 8 | /dataSources.local.xml
28 | 9 |
29 |
30 |
31 | --------------------------------------------------------------------------------
32 | /.idea/PythonPDF2Voice.iml:
33 | --------------------------------------------------------------------------------
34 | 1 |
35 | 2 |
36 | 3 |
37 | 4 |
40 | 6 |
41 | 7 |
42 | 8 |
43 | 9 |
44 | 10 |
45 |
46 |
47 | --------------------------------------------------------------------------------
48 | /.idea/inspectionProfiles/profiles_settings.xml:
49 | --------------------------------------------------------------------------------
50 | 1 |
51 | 2 |
52 | 3 |
53 | 4 |
54 | 5 |
55 | 6 |
56 |
57 |
58 | --------------------------------------------------------------------------------
59 | /.idea/misc.xml:
60 | --------------------------------------------------------------------------------
61 | 1 |
62 | 2 |
63 | 3 |
64 | 4 |
65 | 5 |
66 | 6 |
67 |
68 |
69 | --------------------------------------------------------------------------------
70 | /.idea/modules.xml:
71 | --------------------------------------------------------------------------------
72 | 1 |
73 | 2 |
74 | 3 |
75 | 4 |
76 | 5 |
77 | 6 |
78 | 7 |
79 | 8 |
80 |
81 |
82 | --------------------------------------------------------------------------------
83 | /.idea/vcs.xml:
84 | --------------------------------------------------------------------------------
85 | 1 |
86 | 2 |
87 | 3 |
88 | 4 |
90 | 5 |
91 | 6 |
92 |
93 |
94 | --------------------------------------------------------------------------------
95 | /README.md:
96 | --------------------------------------------------------------------------------
97 | 1 | [](https://uithub.com/MohammadJabiullaS/PythonPDF2Voice/tree/master)
98 | 2 |
99 |
100 |
101 | --------------------------------------------------------------------------------
102 | /src/EntryTextVar.py:
103 | --------------------------------------------------------------------------------
104 | 1 | # Import the necessary module
105 | 2 | import tkinter as tk
106 | 3 |
107 | 4 | def on_text_Chage(*args):
108 | 5 | new_value = text_variable.get()
109 | 6 | print("Entered text:", new_value)
110 | 7 |
111 | 8 | # Create a Tkinter window
112 | 9 | window = tk.Tk()
113 | 10 | window.title("Getting Textvariable from Entry")
114 | 11 |
115 | 12 | # Create a textvariable
116 | 13 | text_variable = tk.StringVar()
117 | 14 | text_variable.trace('w', on_text_Chage)
118 | 15 | # Create an Entry widget associated with the textvariable
119 | 16 | entry = tk.Entry(window, textvariable=text_variable)
120 | 17 | entry.pack()
121 | 18 |
122 | 19 | def retrieve_text():
123 | 20 | # Retrieve the text from the textvariable
124 | 21 | entered_text = text_variable.get()
125 | 22 | print("Entered text:", entered_text)
126 | 23 |
127 | 24 | # Create a button to trigger text retrieval
128 | 25 | button = tk.Button(window, text="Retrieve Text", command=retrieve_text)
129 | 26 | button.pack()
130 | 27 |
131 | 28 | # Run the Tkinter event loop
132 | 29 | window.mainloop()
133 | 30 |
134 | 31 |
135 |
136 |
137 | --------------------------------------------------------------------------------
138 | /src/ISellMyDreams.pdf:
139 | --------------------------------------------------------------------------------
140 | https://raw.githubusercontent.com/MohammadJabiullaS/PythonPDF2Voice/master/src/ISellMyDreams.pdf
141 |
142 |
143 | --------------------------------------------------------------------------------
144 | /src/PDF2Audio2PDF.py:
145 | --------------------------------------------------------------------------------
146 | 1 | from tkinter import *
147 | 2 | import tkinter.messagebox as mb
148 | 3 |
149 | 4 | from path import Path
150 | 5 | from PyPDF4.pdf import PdfFileReader as PDFreader, PdfFileWriter as PDFwriter
151 | 6 | import pyttsx3
152 | 7 | from speech_recognition import Recognizer, AudioFile
153 | 8 | from pydub import AudioSegment
154 | 9 | import os
155 | 10 |
156 | 11 |
157 | 12 | # Initializing the GUI window
158 | 13 | class Window(Tk):
159 | 14 | def __init__(self):
160 | 15 | super(Window, self).__init__()
161 | 16 | self.title("Python PDF to Audio and Audio to PDF converter")
162 | 17 | self.geometry('400x250')
163 | 18 | self.resizable(0, 0)
164 | 19 | self.config(bg='Burlywood')
165 | 20 |
166 | 21 | Label(self, text='Python PDF to Audio and Audio to PDF converter', wraplength=400,
167 | 22 | bg='Burlywood', font=("Courier", 15)).place(x=0, y=0)
168 | 23 |
169 | 24 | Button(self, text="Convert PDF to Audio", font=("Courier", 15), bg='light blue',
170 | 25 | command=self.pdf_to_audio, width=25).place(x=40, y=80)
171 | 26 |
172 | 27 | Button(self, text="Convert Audio to PDF", font=("Courier", 15), bg='light blue',
173 | 28 | command=self.audio_to_pdf, width=25).place(x=40, y=150)
174 | 29 |
175 | 30 | def pdf_to_audio(self):
176 | 31 | pta = Toplevel(self)
177 | 32 | pta.title('Convert PDF to Audio')
178 | 33 | pta.geometry('500x300')
179 | 34 | pta.resizable(0, 0)
180 | 35 | pta.config(bg='Chocolate')
181 | 36 |
182 | 37 | Label(pta, text='Convert PDF to Audio', font=('Courier', 15), bg='Chocolate').place(relx=0.3, y=0)
183 | 38 |
184 | 39 | Label(pta, text='Enter the PDF file location (with extension): ', bg='Chocolate', font=("Verdana", 11)).place(
185 | 40 | x=10, y=60)
186 | 41 | filename = Entry(pta, width=32, font=('Verdana', 11))
187 | 42 | filename.place(x=10, y=90)
188 | 43 |
189 | 44 | Label(pta, text='Enter the page to read from the PDF (only one can be read): ', bg='Chocolate',
190 | 45 | font=("Verdana", 11)).place(x=10, y=140)
191 | 46 | page = Entry(pta, width=15, font=('Verdana', 11))
192 | 47 | page.place(x=10, y=170)
193 | 48 |
194 | 49 | Button(pta, text='Speak the text', font=('Gill Sans MT', 12), bg='Snow', width=20,
195 | 50 | command=lambda: self.speak_text(filename.get(), page.get())).place(x=150, y=240)
196 | 51 |
197 | 52 | def audio_to_pdf(self):
198 | 53 | atp = Toplevel(self)
199 | 54 | atp.title('Convert Audio to PDF')
200 | 55 | atp.geometry('675x300')
201 | 56 | atp.resizable(0, 0)
202 | 57 | atp.config(bg='FireBrick')
203 | 58 |
204 | 59 | Label(atp, text='Convert Audio to PDF', font=("Courier", 15), bg='FireBrick').place(relx=0.36, y=0)
205 | 60 |
206 | 61 | Label(atp, text='Enter the Audio File location that you want to read [in .wav or .mp3 extensions only]:',
207 | 62 | bg='FireBrick', font=('Verdana', 11)).place(x=20, y=60)
208 | 63 | audiofile = Entry(atp, width=58, font=('Verdana', 11))
209 | 64 | audiofile.place(x=20, y=90)
210 | 65 |
211 | 66 | Label(atp, text='Enter the PDF File location that you want to save the text in (with extension):',
212 | 67 | bg='FireBrick', font=('Verdana', 11)).place(x=20, y=140)
213 | 68 | pdffile = Entry(atp, width=58, font=('Verdana', 11))
214 | 69 | pdffile.place(x=20, y=170)
215 | 70 |
216 | 71 | Button(atp, text='Create PDF', bg='Snow', font=('Gill Sans MT', 12), width=20,
217 | 72 | command=lambda: self.speech_recognition(audiofile.get(), pdffile.get())).place(x=247, y=230)
218 | 73 |
219 | 74 | @staticmethod
220 | 75 | def speak_text(filename, page):
221 | 76 | if not filename or not page:
222 | 77 | mb.showerror('Missing field!', 'Please check your responses, because one of the fields is missing')
223 | 78 | return
224 | 79 |
225 | 80 | reader = PDFreader(filename)
226 | 81 | engine = pyttsx3.init()
227 | 82 |
228 | 83 | with Path(filename).open('rb'):
229 | 84 | page_to_read = reader.getPage(int(page) - 1)
230 | 85 | text = page_to_read.extractText()
231 | 86 |
232 | 87 | engine.say(text)
233 | 88 | engine.runAndWait()
234 | 89 |
235 | 90 | @staticmethod
236 | 91 | def write_text(filename, text):
237 | 92 | writer = PDFwriter()
238 | 93 | writer.addBlankPage(72, 72)
239 | 94 |
240 | 95 | pdf_path = Path(filename)
241 | 96 |
242 | 97 | with pdf_path.open('ab') as output_file:
243 | 98 | writer.write(output_file)
244 | 99 | output_file.write(text)
245 | 100 |
246 | 101 | def speech_recognition(self, audio, pdf):
247 | 102 | if not audio or not pdf:
248 | 103 | mb.showerror('Missing field!', 'Please check your responses, because one of the fields is missing')
249 | 104 | return
250 | 105 |
251 | 106 | audio_file_name = os.path.basename(audio).split('.')[0]
252 | 107 | audio_file_extension = os.path.basename(audio).split('.')[1]
253 | 108 |
254 | 109 | if audio_file_extension != 'wav' and audio_file_extension != 'mp3':
255 | 110 | mb.showerror('Error!', 'The format of the audio file should only be either "wav" and "mp3"!')
256 | 111 |
257 | 112 | if audio_file_extension == 'mp3':
258 | 113 | audio_file = AudioSegment.from_file(Path(audio), format='mp3')
259 | 114 | audio_file.export(f'{audio_file_name}.wav', format='wav')
260 | 115 |
261 | 116 | source_file = f'{audio_file_name}.wav'
262 | 117 |
263 | 118 | r = Recognizer()
264 | 119 | with AudioFile(source_file) as source:
265 | 120 | r.pause_threshold = 5
266 | 121 | speech = r.record(source)
267 | 122 |
268 | 123 | text = r.recognize_google(speech)
269 | 124 |
270 | 125 | self.write_text(pdf, text)
271 | 126 |
272 | 127 |
273 | 128 | # Finalizing the GUI window
274 | 129 | app = Window()
275 | 130 |
276 | 131 | app.update()
277 | 132 | app.mainloop()
278 |
279 |
280 | --------------------------------------------------------------------------------
281 | /src/pdf2speech.py:
282 | --------------------------------------------------------------------------------
283 | 1 | import PyPDF2
284 | 2 | import pyttsx3
285 | 3 | from pyttsx3 import speak
286 | 4 |
287 | 5 | from src.PDF2Audio2PDF import pdfPath
288 | 6 |
289 | 7 | #choose file path
290 | 8 | filePath = open('samplepdf.pdf', 'rb')
291 | 9 | pdfReader = PyPDF2.PdfReader(filePath)
292 | 10 |
293 | 11 | from_page = pdfReader.pages[2]
294 | 12 | text = from_page.extract_text()
295 | 13 |
296 | 14 | speak = pyttsx3.init()
297 | 15 | speak.say(text)
298 | 16 | speak.runAndWait()
299 | 17 |
300 | 18 |
301 |
302 |
303 | --------------------------------------------------------------------------------
304 | /src/samplepdf.pdf:
305 | --------------------------------------------------------------------------------
306 | https://raw.githubusercontent.com/MohammadJabiullaS/PythonPDF2Voice/master/src/samplepdf.pdf
307 |
308 |
309 | --------------------------------------------------------------------------------
310 |
--------------------------------------------------------------------------------
/src/EntryTextVar.py:
--------------------------------------------------------------------------------
1 | # Import the necessary module
2 | import tkinter as tk
3 |
4 | def on_text_Chage(*args):
5 | new_value = text_variable.get()
6 | print("Entered text:", new_value)
7 |
8 | # Create a Tkinter window
9 | window = tk.Tk()
10 | window.title("Getting Textvariable from Entry")
11 |
12 | # Create a textvariable
13 | text_variable = tk.StringVar()
14 | text_variable.trace('w', on_text_Chage)
15 | # Create an Entry widget associated with the textvariable
16 | entry = tk.Entry(window, textvariable=text_variable)
17 | entry.pack()
18 |
19 | def retrieve_text():
20 | # Retrieve the text from the textvariable
21 | entered_text = text_variable.get()
22 | print("Entered text:", entered_text)
23 |
24 | # Create a button to trigger text retrieval
25 | button = tk.Button(window, text="Retrieve Text", command=retrieve_text)
26 | button.pack()
27 |
28 | # Run the Tkinter event loop
29 | window.mainloop()
30 |
31 |
--------------------------------------------------------------------------------
/src/ISellMyDreams.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MohammadJabiullaS/PythonPDF2Voice/master/src/ISellMyDreams.pdf
--------------------------------------------------------------------------------
/src/PDF2Audio2PDF.py:
--------------------------------------------------------------------------------
1 | from tkinter import *
2 | import tkinter.messagebox as mb
3 |
4 | from path import Path
5 | from PyPDF4.pdf import PdfFileReader as PDFreader, PdfFileWriter as PDFwriter
6 | import pyttsx3
7 | from speech_recognition import Recognizer, AudioFile
8 | from pydub import AudioSegment
9 | import os
10 |
11 |
12 | # Initializing the GUI window
13 | class Window(Tk):
14 | def __init__(self):
15 | super(Window, self).__init__()
16 | self.title("Python PDF to Audio and Audio to PDF converter")
17 | self.geometry('400x250')
18 | self.resizable(0, 0)
19 | self.config(bg='Burlywood')
20 |
21 | Label(self, text='Python PDF to Audio and Audio to PDF converter', wraplength=400,
22 | bg='Burlywood', font=("Courier", 15)).place(x=0, y=0)
23 |
24 | Button(self, text="Convert PDF to Audio", font=("Courier", 15), bg='light blue',
25 | command=self.pdf_to_audio, width=25).place(x=40, y=80)
26 |
27 | Button(self, text="Convert Audio to PDF", font=("Courier", 15), bg='light blue',
28 | command=self.audio_to_pdf, width=25).place(x=40, y=150)
29 |
30 | def pdf_to_audio(self):
31 | pta = Toplevel(self)
32 | pta.title('Convert PDF to Audio')
33 | pta.geometry('500x300')
34 | pta.resizable(0, 0)
35 | pta.config(bg='Chocolate')
36 |
37 | Label(pta, text='Convert PDF to Audio', font=('Courier', 15), bg='Chocolate').place(relx=0.3, y=0)
38 |
39 | Label(pta, text='Enter the PDF file location (with extension): ', bg='Chocolate', font=("Verdana", 11)).place(
40 | x=10, y=60)
41 | filename = Entry(pta, width=32, font=('Verdana', 11))
42 | filename.place(x=10, y=90)
43 |
44 | Label(pta, text='Enter the page to read from the PDF (only one can be read): ', bg='Chocolate',
45 | font=("Verdana", 11)).place(x=10, y=140)
46 | page = Entry(pta, width=15, font=('Verdana', 11))
47 | page.place(x=10, y=170)
48 |
49 | Button(pta, text='Speak the text', font=('Gill Sans MT', 12), bg='Snow', width=20,
50 | command=lambda: self.speak_text(filename.get(), page.get())).place(x=150, y=240)
51 |
52 | def audio_to_pdf(self):
53 | atp = Toplevel(self)
54 | atp.title('Convert Audio to PDF')
55 | atp.geometry('675x300')
56 | atp.resizable(0, 0)
57 | atp.config(bg='FireBrick')
58 |
59 | Label(atp, text='Convert Audio to PDF', font=("Courier", 15), bg='FireBrick').place(relx=0.36, y=0)
60 |
61 | Label(atp, text='Enter the Audio File location that you want to read [in .wav or .mp3 extensions only]:',
62 | bg='FireBrick', font=('Verdana', 11)).place(x=20, y=60)
63 | audiofile = Entry(atp, width=58, font=('Verdana', 11))
64 | audiofile.place(x=20, y=90)
65 |
66 | Label(atp, text='Enter the PDF File location that you want to save the text in (with extension):',
67 | bg='FireBrick', font=('Verdana', 11)).place(x=20, y=140)
68 | pdffile = Entry(atp, width=58, font=('Verdana', 11))
69 | pdffile.place(x=20, y=170)
70 |
71 | Button(atp, text='Create PDF', bg='Snow', font=('Gill Sans MT', 12), width=20,
72 | command=lambda: self.speech_recognition(audiofile.get(), pdffile.get())).place(x=247, y=230)
73 |
74 | @staticmethod
75 | def speak_text(filename, page):
76 | if not filename or not page:
77 | mb.showerror('Missing field!', 'Please check your responses, because one of the fields is missing')
78 | return
79 |
80 | reader = PDFreader(filename)
81 | engine = pyttsx3.init()
82 |
83 | with Path(filename).open('rb'):
84 | page_to_read = reader.getPage(int(page) - 1)
85 | text = page_to_read.extractText()
86 |
87 | engine.say(text)
88 | engine.runAndWait()
89 |
90 | @staticmethod
91 | def write_text(filename, text):
92 | writer = PDFwriter()
93 | writer.addBlankPage(72, 72)
94 |
95 | pdf_path = Path(filename)
96 |
97 | with pdf_path.open('ab') as output_file:
98 | writer.write(output_file)
99 | output_file.write(text)
100 |
101 | def speech_recognition(self, audio, pdf):
102 | if not audio or not pdf:
103 | mb.showerror('Missing field!', 'Please check your responses, because one of the fields is missing')
104 | return
105 |
106 | audio_file_name = os.path.basename(audio).split('.')[0]
107 | audio_file_extension = os.path.basename(audio).split('.')[1]
108 |
109 | if audio_file_extension != 'wav' and audio_file_extension != 'mp3':
110 | mb.showerror('Error!', 'The format of the audio file should only be either "wav" and "mp3"!')
111 |
112 | if audio_file_extension == 'mp3':
113 | audio_file = AudioSegment.from_file(Path(audio), format='mp3')
114 | audio_file.export(f'{audio_file_name}.wav', format='wav')
115 |
116 | source_file = f'{audio_file_name}.wav'
117 |
118 | r = Recognizer()
119 | with AudioFile(source_file) as source:
120 | r.pause_threshold = 5
121 | speech = r.record(source)
122 |
123 | text = r.recognize_google(speech)
124 |
125 | self.write_text(pdf, text)
126 |
127 |
128 | # Finalizing the GUI window
129 | app = Window()
130 |
131 | app.update()
132 | app.mainloop()
--------------------------------------------------------------------------------
/src/pdf2speech.py:
--------------------------------------------------------------------------------
1 | import PyPDF2
2 | import pyttsx3
3 | from pyttsx3 import speak
4 |
5 | from src.PDF2Audio2PDF import pdfPath
6 |
7 | #choose file path
8 | filePath = open('samplepdf.pdf', 'rb')
9 | pdfReader = PyPDF2.PdfReader(filePath)
10 |
11 | from_page = pdfReader.pages[2]
12 | text = from_page.extract_text()
13 |
14 | speak = pyttsx3.init()
15 | speak.say(text)
16 | speak.runAndWait()
17 |
18 |
--------------------------------------------------------------------------------
/src/samplepdf.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/MohammadJabiullaS/PythonPDF2Voice/master/src/samplepdf.pdf
--------------------------------------------------------------------------------