Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import io
|
|
4 |
import os
|
5 |
import time
|
6 |
from gtts.lang import _main_langs
|
|
|
7 |
|
8 |
AUDIO_DIR = 'audio_files'
|
9 |
MAX_FILE_AGE = 24 * 60 * 60 # maximum age of audio files in seconds (24 hours)
|
@@ -41,6 +42,12 @@ def txt_to_speech(file, lang, tld):
|
|
41 |
text = f.read()
|
42 |
return text_to_speech(text, lang, tld)
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
# Tạo giao diện Gradio với tab
|
45 |
with gr.Blocks() as iface:
|
46 |
with gr.Tab("Text to Speech"):
|
@@ -65,4 +72,15 @@ with gr.Blocks() as iface:
|
|
65 |
inputs=[file_input, lang_input_file, tld_input_file],
|
66 |
outputs=[audio_output_file, file_output_file])
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
iface.launch(enable_queue=True)
|
|
|
4 |
import os
|
5 |
import time
|
6 |
from gtts.lang import _main_langs
|
7 |
+
from docx import Document # Thêm thư viện này để làm việc với tệp docx
|
8 |
|
9 |
AUDIO_DIR = 'audio_files'
|
10 |
MAX_FILE_AGE = 24 * 60 * 60 # maximum age of audio files in seconds (24 hours)
|
|
|
42 |
text = f.read()
|
43 |
return text_to_speech(text, lang, tld)
|
44 |
|
45 |
+
# Hàm chuyển đổi file .docx thành giọng nói
|
46 |
+
def docx_to_speech(file, lang, tld):
|
47 |
+
doc = Document(file.name)
|
48 |
+
text = "\n".join([para.text for para in doc.paragraphs]) # Lấy tất cả văn bản từ các đoạn
|
49 |
+
return text_to_speech(text, lang, tld)
|
50 |
+
|
51 |
# Tạo giao diện Gradio với tab
|
52 |
with gr.Blocks() as iface:
|
53 |
with gr.Tab("Text to Speech"):
|
|
|
72 |
inputs=[file_input, lang_input_file, tld_input_file],
|
73 |
outputs=[audio_output_file, file_output_file])
|
74 |
|
75 |
+
with gr.Tab("DOCX to Speech"):
|
76 |
+
gr.Markdown("### Convert .docx file to speech")
|
77 |
+
docx_file_input = gr.File(label="Upload your .docx file")
|
78 |
+
lang_input_docx = gr.Dropdown(choices=list(_main_langs().values()), label="Select language:")
|
79 |
+
tld_input_docx = gr.Dropdown(choices=["com", "co.uk", "ca"], label="Select TLD:", value="com") # Bạn có thể điều chỉnh TLD
|
80 |
+
|
81 |
+
audio_output_docx, file_output_docx = gr.Audio(label="Audio"), gr.File(label="Audio File")
|
82 |
+
gr.Button("Convert").click(fn=lambda file, lang, tld: docx_to_speech(file, lang, tld),
|
83 |
+
inputs=[docx_file_input, lang_input_docx, tld_input_docx],
|
84 |
+
outputs=[audio_output_docx, file_output_docx])
|
85 |
+
|
86 |
iface.launch(enable_queue=True)
|