TDN-M commited on
Commit
c5adb9e
·
verified ·
1 Parent(s): a5481e4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -4
app.py CHANGED
@@ -18,9 +18,8 @@ if not os.path.exists(VOICES_DIR):
18
  else:
19
  voice_files = [os.path.join(VOICES_DIR, f) for f in os.listdir(VOICES_DIR) if f.endswith(".wav")]
20
  print(f"Các file âm thanh trong thư mục {VOICES_DIR}: {voice_files}")
21
- for voice_file in voice_files:
22
- if not os.access(voice_file, os.R_OK):
23
- print(f"Không có quyền đọc file: {voice_file}")
24
 
25
  def create_docx(content, output_path):
26
  """
@@ -70,8 +69,11 @@ def convert_content_to_speech(content, voice_file):
70
  """
71
  Chuyển đổi nội dung thành giọng nói.
72
  """
 
73
  if content is None or content.strip() == "":
74
  return "Lỗi: Nội dung trống hoặc không hợp lệ."
 
 
75
  return text_to_speech(content, voice_file)
76
 
77
  def interface():
@@ -87,7 +89,10 @@ def interface():
87
  choices=CONTENT_TYPES,
88
  value=None) # Giá trị mặc định là không có gì được chọn
89
  voice_files = [os.path.join(VOICES_DIR, f) for f in os.listdir(VOICES_DIR) if f.endswith(".wav")]
90
- voice_selector = gr.Dropdown(label="Chọn giọng đọc", choices=voice_files) # Dropdown để chọn file âm thanh
 
 
 
91
  content_button = gr.Button("Tạo Nội dung")
92
 
93
  with gr.Column():
 
18
  else:
19
  voice_files = [os.path.join(VOICES_DIR, f) for f in os.listdir(VOICES_DIR) if f.endswith(".wav")]
20
  print(f"Các file âm thanh trong thư mục {VOICES_DIR}: {voice_files}")
21
+ if not voice_files:
22
+ print(f"Không file âm thanh nào trong thư mục {VOICES_DIR}.")
 
23
 
24
  def create_docx(content, output_path):
25
  """
 
69
  """
70
  Chuyển đổi nội dung thành giọng nói.
71
  """
72
+ print(f"Giá trị của voice_file: {voice_file}") # Log giá trị của voice_file
73
  if content is None or content.strip() == "":
74
  return "Lỗi: Nội dung trống hoặc không hợp lệ."
75
+ if voice_file is None:
76
+ return "Lỗi: Vui lòng chọn file âm thanh mẫu."
77
  return text_to_speech(content, voice_file)
78
 
79
  def interface():
 
89
  choices=CONTENT_TYPES,
90
  value=None) # Giá trị mặc định là không có gì được chọn
91
  voice_files = [os.path.join(VOICES_DIR, f) for f in os.listdir(VOICES_DIR) if f.endswith(".wav")]
92
+ if voice_files:
93
+ voice_selector = gr.Dropdown(label="Chọn giọng đọc", choices=voice_files, value=voice_files[0]) # Đặt giá trị mặc định
94
+ else:
95
+ voice_selector = gr.Dropdown(label="Chọn giọng đọc", choices=[], value=None) # Nếu không có file, để trống
96
  content_button = gr.Button("Tạo Nội dung")
97
 
98
  with gr.Column():