Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f8dc964

Browse files
saves file into mp3 format as well
1 parent 7a053a6 commit f8dc964

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

‎PDF_to_audio/pdf_to_audio.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import PyPDF2
88
import pyttsx3
9+
from gtts import gTTS #pip install gTTS
910
from tkinter import Tk
1011
from tkinter.filedialog import askopenfilename
1112

@@ -15,10 +16,14 @@
1516

1617
with open(FILE_PATH, "rb") as f: # open the file in reading (rb) mode and call it f
1718
pdf = PyPDF2.PdfFileReader(f)
19+
txt_file=' ' #str variable
1820
#parse every page
1921
for page in pdf.pages:
2022
text = page.extractText()
23+
txt_file+=text #stores text into txt_file variable and convert it into str form as gtts library only saves text file into mp3
2124
## speaking part ####
2225
engine = pyttsx3.init()
2326
engine.say(text)
2427
engine.runAndWait()
28+
audio_file = gTTS(text = txt_file, lang='en') #stores into variable
29+
audio_file.save(FILE_PATH.split('.')[0]+".mp3") #saves into mp3 format with the same name of pdf in the same directory where pdf is

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /