|
import streamlit as st |
|
from gtts import gTTS |
|
from io import BytesIO |
|
from PyPDF2 import PdfReader |
|
|
|
st.image('OIG3 (4).jpeg', caption='Your host on this PDF-to-Speech adventure!') |
|
|
|
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: |
|
|
|
reader = PdfReader(uploaded_file) |
|
|
|
X = len(reader.pages) |
|
print(X) |
|
|
|
i = 0 |
|
while i <= X: |
|
|
|
page = reader.pages[i] |
|
|
|
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) |
|
|