-
Notifications
You must be signed in to change notification settings - Fork 785
/
read.py
57 lines (41 loc) · 1.04 KB
/
read.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
####
# Run the following on terminal:
# pip install streamlit
# Install any other pacakges as required
####
import PyPDF2
import streamlit as st
from gtts import gTTS
from io import BytesIO
def speakText(text):
sound_file = BytesIO()
tts = gTTS(text, lang='en')
tts.write_to_fp(sound_file)
st.audio(sound_file)
def extractText(pdfPath):
pdfReader = PyPDF2.PdfReader(pdfPath)
text = ""
for pageObj in pdfReader.pages:
st.write("Reading PDF ..")
text += pageObj.extract_text()
return text
def readPDF(pdf):
text = extractText(pdf)
speakText(text)
pdfReader, textReader = st.columns(2)
with pdfReader:
st.write("""
# PDF Reader
Helps blind people read a PDF document.
""")
uploaded_pdf = st.file_uploader("Upload your PDF", type = "pdf")
if uploaded_pdf:
readPDF(uploaded_pdf)
with textReader:
st.write("""
# Text Reader
Helps blind people read a piece of text.
""")
text = st.text_input(label = "To read")
if text:
speakText(text)