Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,16 @@ client = OpenAI(api_key=os.environ.get('OPENAI_API_KEY'))
|
|
12 |
# Đường dẫn đến thư mục chứa các file âm thanh
|
13 |
VOICES_DIR = "voices"
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def create_docx(content, output_path):
|
16 |
"""
|
17 |
Tạo file docx từ nội dung.
|
@@ -45,8 +55,9 @@ def text_to_speech(content, voice_file):
|
|
45 |
Chuyển đổi nội dung thành giọng nói bằng hàm generate_speech từ tts.py.
|
46 |
"""
|
47 |
try:
|
|
|
48 |
if voice_file is None or not os.path.exists(voice_file):
|
49 |
-
return "Lỗi: File âm thanh mẫu không tồn tại hoặc không hợp lệ."
|
50 |
|
51 |
print(f"Chuyển đổi nội dung thành giọng nói: {content}") # Log nội dung trước khi chuyển đổi
|
52 |
output_audio = generate_speech(content, language="vi", speaker_wav=voice_file)
|
|
|
12 |
# Đường dẫn đến thư mục chứa các file âm thanh
|
13 |
VOICES_DIR = "voices"
|
14 |
|
15 |
+
# Kiểm tra thư mục voices và các file trong đó
|
16 |
+
if not os.path.exists(VOICES_DIR):
|
17 |
+
print(f"Thư mục {VOICES_DIR} không tồn tại.")
|
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 |
"""
|
27 |
Tạo file docx từ nội dung.
|
|
|
55 |
Chuyển đổi nội dung thành giọng nói bằng hàm generate_speech từ tts.py.
|
56 |
"""
|
57 |
try:
|
58 |
+
print(f"Đường dẫn file âm thanh mẫu: {voice_file}") # Log đường dẫn file
|
59 |
if voice_file is None or not os.path.exists(voice_file):
|
60 |
+
return f"Lỗi: File âm thanh mẫu không tồn tại hoặc không hợp lệ. Đường dẫn: {voice_file}"
|
61 |
|
62 |
print(f"Chuyển đổi nội dung thành giọng nói: {content}") # Log nội dung trước khi chuyển đổi
|
63 |
output_audio = generate_speech(content, language="vi", speaker_wav=voice_file)
|