vuxuanhoan commited on
Commit
413c470
·
verified ·
1 Parent(s): 3f38a74

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -1,25 +1,25 @@
1
  import gradio as gr
2
- import edge_tts # Thêm thư viện Edge TTS
3
  import io
4
  import os
5
  import time
6
  import asyncio
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)
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) # Chọn giọng nói tương ứng với ngôn ngữ
15
  fp = io.BytesIO()
16
 
17
- # Lưu âm thanh vào bộ nhớ và lưu tệp vào AUDIO_DIR
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' # Đổi định dạng thành 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:") # Thay đổi danh sách giọng nói cho phù hợp
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