Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -35,6 +35,12 @@ def delete_old_audio_files():
|
|
35 |
if now - os.path.getmtime(file_path) > MAX_FILE_AGE:
|
36 |
os.remove(file_path)
|
37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
# Tạo giao diện Gradio với tab
|
39 |
with gr.Blocks() as iface:
|
40 |
with gr.Tab("Text to Speech"):
|
@@ -48,4 +54,15 @@ with gr.Blocks() as iface:
|
|
48 |
inputs=[text_input, lang_input, tld_input],
|
49 |
outputs=[audio_output, file_output])
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
iface.launch(enable_queue=True)
|
|
|
35 |
if now - os.path.getmtime(file_path) > MAX_FILE_AGE:
|
36 |
os.remove(file_path)
|
37 |
|
38 |
+
# Hàm chuyển đổi file .txt thành giọng nói
|
39 |
+
def txt_to_speech(file, lang, tld):
|
40 |
+
with open(file.name, 'r') as f:
|
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"):
|
|
|
54 |
inputs=[text_input, lang_input, tld_input],
|
55 |
outputs=[audio_output, file_output])
|
56 |
|
57 |
+
with gr.Tab("TXT to Speech"):
|
58 |
+
gr.Markdown("### Convert .txt file to speech")
|
59 |
+
file_input = gr.File(label="Upload your .txt file")
|
60 |
+
lang_input_file = gr.Dropdown(choices=list(_main_langs().values()), label="Select language:")
|
61 |
+
tld_input_file = gr.Dropdown(choices=["com", "co.uk", "ca"], label="Select TLD:", value="com") # Bạn có thể điều chỉnh TLD
|
62 |
+
|
63 |
+
audio_output_file, file_output_file = gr.Audio(label="Audio"), gr.File(label="Audio File")
|
64 |
+
gr.Button("Convert").click(fn=lambda file, lang, tld: txt_to_speech(file, lang, tld),
|
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)
|