Spaces:
Runtime error
Runtime error
Commit
•
d8aea8b
1
Parent(s):
347336e
Rename pdf_to_audio.py to app.py
Browse files- pdf_to_audio.py → app.py +28 -1
pdf_to_audio.py → app.py
RENAMED
@@ -75,4 +75,31 @@ if __name__ == "__main__":
|
|
75 |
tts = QuantizedSpeechT5TTSPipe()
|
76 |
sample_text = 'Hello world! This is a test.'
|
77 |
result = tts.generate(sample_text)
|
78 |
-
print(f'Generated {len(result)} audio files from "{sample_text}"')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
tts = QuantizedSpeechT5TTSPipe()
|
76 |
sample_text = 'Hello world! This is a test.'
|
77 |
result = tts.generate(sample_text)
|
78 |
+
print(f'Generated {len(result)} audio files from "{sample_text}"')
|
79 |
+
|
80 |
+
def main(pdf_file: gr.File, output_filename: str):
|
81 |
+
start_time = time.time()
|
82 |
+
pdf_text = convert_pdf_to_text(pdf_file)
|
83 |
+
print(f'Processed PDF content in {time.time() - start_time:.4f} seconds')
|
84 |
+
|
85 |
+
pipe = QuantizedSpeechT5TTSPipe()
|
86 |
+
start_time = time.time()
|
87 |
+
audios = pipe.generate(pdf_text)
|
88 |
+
print(f'Generated {len(audios)} audio files in {time.time() - start_time:.4f} seconds')
|
89 |
+
|
90 |
+
zip_buffer = BytesIO()
|
91 |
+
with ZipFile(zip_buffer, mode='w') as zf:
|
92 |
+
for i, audio in enumerate(audios):
|
93 |
+
filename = f"{i}_{output_filename}.wav"
|
94 |
+
zf.writestr(filename, audio)
|
95 |
+
zip_buffer.seek(0)
|
96 |
+
|
97 |
+
return {'zip': zip_buffer}
|
98 |
+
|
99 |
+
iface = gr.Interface(fn=main,
|
100 |
+
inputs="file",
|
101 |
+
outputs="binary",
|
102 |
+
input_types=['pdf'],
|
103 |
+
output_types=['download'])
|
104 |
+
|
105 |
+
iface.launch()
|