Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
-
import edge_tts
|
3 |
import io
|
4 |
import os
|
5 |
import time
|
6 |
import asyncio
|
7 |
-
from docx import Document
|
8 |
|
9 |
AUDIO_DIR = 'audio_files'
|
10 |
MAX_FILE_AGE = 24 * 60 * 60 # maximum age of audio files in seconds (24 hours)
|
11 |
|
12 |
# Hàm chuyển đổi văn bản thành giọng nói sử dụng Edge TTS
|
13 |
async def text_to_speech(text, lang):
|
14 |
-
tts = edge_tts.Communicate(text, voice=lang)
|
15 |
fp = io.BytesIO()
|
16 |
|
17 |
-
# Lưu âm thanh vào bộ nhớ
|
18 |
await tts.save(fp, 'audio/mp3') # Định dạng mp3
|
19 |
fp.seek(0)
|
20 |
|
21 |
os.makedirs(AUDIO_DIR, exist_ok=True) # Đảm bảo thư mục tồn tại
|
22 |
-
file_name = str(time.time()) + '.mp3'
|
23 |
file_path = os.path.join(AUDIO_DIR, file_name)
|
24 |
|
25 |
# Lưu tệp âm thanh vào thư mục AUDIO_DIR
|
@@ -53,7 +53,7 @@ with gr.Blocks() as iface:
|
|
53 |
with gr.Tab("Text to Speech"):
|
54 |
gr.Markdown("### Convert text to speech")
|
55 |
text_input = gr.Textbox(lines=10, label="Enter your text here:")
|
56 |
-
lang_input = gr.Dropdown(choices=["vi-VN-NamMinhNeural", "en-US-JennyNeural"], label="Select language:")
|
57 |
|
58 |
audio_output, file_output = gr.Audio(label="Audio"), gr.File(label="Audio File")
|
59 |
|
|
|
1 |
import gradio as gr
|
2 |
+
import edge_tts
|
3 |
import io
|
4 |
import os
|
5 |
import time
|
6 |
import asyncio
|
7 |
+
from docx import Document
|
8 |
|
9 |
AUDIO_DIR = 'audio_files'
|
10 |
MAX_FILE_AGE = 24 * 60 * 60 # maximum age of audio files in seconds (24 hours)
|
11 |
|
12 |
# Hàm chuyển đổi văn bản thành giọng nói sử dụng Edge TTS
|
13 |
async def text_to_speech(text, lang):
|
14 |
+
tts = edge_tts.Communicate(text, voice=lang)
|
15 |
fp = io.BytesIO()
|
16 |
|
17 |
+
# Lưu âm thanh vào bộ nhớ
|
18 |
await tts.save(fp, 'audio/mp3') # Định dạng mp3
|
19 |
fp.seek(0)
|
20 |
|
21 |
os.makedirs(AUDIO_DIR, exist_ok=True) # Đảm bảo thư mục tồn tại
|
22 |
+
file_name = str(time.time()) + '.mp3'
|
23 |
file_path = os.path.join(AUDIO_DIR, file_name)
|
24 |
|
25 |
# Lưu tệp âm thanh vào thư mục AUDIO_DIR
|
|
|
53 |
with gr.Tab("Text to Speech"):
|
54 |
gr.Markdown("### Convert text to speech")
|
55 |
text_input = gr.Textbox(lines=10, label="Enter your text here:")
|
56 |
+
lang_input = gr.Dropdown(choices=["vi-VN-NamMinhNeural", "en-US-JennyNeural"], label="Select language:")
|
57 |
|
58 |
audio_output, file_output = gr.Audio(label="Audio"), gr.File(label="Audio File")
|
59 |
|