File size: 1,147 Bytes
474f4cc
cc84c76
 
9f8e59c
474f4cc
 
4b5b0e4
 
 
ac5edc7
9f8e59c
 
 
29a0691
 
 
ad135b5
29a0691
 
 
 
 
 
589c7da
44e6c56
9f8e59c
44e6c56
29a0691
44e6c56
589c7da
ac5edc7
 
cc84c76
e2bb816
 
b56acb6
0acfb8a
 
 
 
 
 
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
import streamlit as st
from gtts import gTTS 
from io import BytesIO
from PyPDF2 import PdfReader

x = st.slider('Select a value')
slider_reply = x, 'squared is', x * x
st.write(slider_reply)

uploaded_file = st.file_uploader("Choose a file", "pdf")
if uploaded_file is not None: 
    # creating a pdf reader object
    reader = PdfReader(uploaded_file)
    # printing number of pages in pdf file
    X = len(reader.pages)
    print(X)

    i = 0
    while i <= X:
        # getting a specific page from the pdf file
        page = reader.pages[i]
        # extracting text from page
        text = page.extract_text()  
        print("Created text of page", i )
        sound_file = BytesIO()
        tts = gTTS(text, lang='en')
        tts.write_to_fp(sound_file)
        i = i + 1
        st.audio(sound_file)
        print("transcribed", i, "pages of", X, "total pages.")
            
    

prompt = st.chat_input("Say something")
if prompt:
    st.write(prompt)
    with st.popover("Open popover"):
        sound_file = BytesIO()
        tts = gTTS(prompt, lang='en')
        tts.write_to_fp(sound_file)
        
        st.audio(sound_file)