Solshine commited on
Commit
6d916f4
β€’
1 Parent(s): a1f5b6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -2,6 +2,9 @@ import streamlit as st
2
  from gtts import gTTS
3
  from io import BytesIO
4
  from PyPDF2 import PdfReader
 
 
 
5
 
6
  st.image('OIG3 (4).jpeg', caption='Your host on this PDF-to-Speech adventure!')
7
 
@@ -22,10 +25,19 @@ if uploaded_file is not None:
22
  # extracting text from page
23
  text = page.extract_text()
24
  print("Created text of page", i )
25
- sound_file = BytesIO()
26
- tts = gTTS(text, lang='en')
27
- tts.write_to_fp(sound_file)
28
- st.audio(sound_file)
 
 
 
 
 
 
 
 
 
29
  print("Read aloud", i, "pages of", X, "total pages.")
30
  i = i + 1
31
  st.write("πŸŽ‰ That's the whole PDF! Have an awesome day! πŸŽ‰")
 
2
  from gtts import gTTS
3
  from io import BytesIO
4
  from PyPDF2 import PdfReader
5
+ from whisperspeech.pipeline import Pipeline
6
+
7
+ pipe = Pipeline(torch_compile=True)
8
 
9
  st.image('OIG3 (4).jpeg', caption='Your host on this PDF-to-Speech adventure!')
10
 
 
25
  # extracting text from page
26
  text = page.extract_text()
27
  print("Created text of page", i )
28
+
29
+ # Generate audio for the current page using a unique filename
30
+ page_audio_file = f"output_{i}.wav"
31
+ pipe.generate_to_file(page_audio_file, text)
32
+
33
+ # Display the generated audio using st.audio
34
+ with open(page_audio_file, "rb") as audio_file:
35
+ st.audio(audio_file)
36
+
37
+ # sound_file = BytesIO()
38
+ # tts = gTTS(text, lang='en')
39
+ # tts.write_to_fp(sound_file)
40
+ # st.audio(sound_file)
41
  print("Read aloud", i, "pages of", X, "total pages.")
42
  i = i + 1
43
  st.write("πŸŽ‰ That's the whole PDF! Have an awesome day! πŸŽ‰")