Spaces:
Running
Running
Upload 2 files
Browse files- app.py +36 -0
- requirements.txt +4 -0
app.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from PyPDF2 import PdfReader
|
3 |
+
from gtts import gTTS
|
4 |
+
from pydub import AudioSegment
|
5 |
+
from pydub.playback import play
|
6 |
+
import gradio as gr
|
7 |
+
|
8 |
+
def pdf_to_text(pdf_file):
|
9 |
+
reader = PdfReader(pdf_file)
|
10 |
+
text = ""
|
11 |
+
for page in reader.pages:
|
12 |
+
text += page.extract_text()
|
13 |
+
return text
|
14 |
+
|
15 |
+
def text_to_speech(text, lang='en'):
|
16 |
+
tts = gTTS(text=text, lang=lang)
|
17 |
+
tts.save("output.mp3")
|
18 |
+
sound = AudioSegment.from_mp3("output.mp3")
|
19 |
+
return sound
|
20 |
+
|
21 |
+
def convert_pdf_to_speech(pdf_file):
|
22 |
+
text = pdf_to_text(pdf_file)
|
23 |
+
sound = text_to_speech(text)
|
24 |
+
return sound
|
25 |
+
|
26 |
+
def play_audio(audio_segment):
|
27 |
+
play(audio_segment)
|
28 |
+
|
29 |
+
# Gradio arayüzü
|
30 |
+
def interface(pdf_file):
|
31 |
+
audio_segment = convert_pdf_to_speech(pdf_file.name)
|
32 |
+
play_audio(audio_segment)
|
33 |
+
return "Seslendirme tamamlandı."
|
34 |
+
|
35 |
+
iface = gr.Interface(fn=interface, inputs="file", outputs="text")
|
36 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
PyPDF2
|
2 |
+
gTTS
|
3 |
+
pydub
|
4 |
+
gradio
|