Update app.py
Browse files
app.py
CHANGED
@@ -634,24 +634,30 @@ def apply_glossary_tooltips(text):
|
|
634 |
html_output = f'<div style="padding: 10px; line-height: 1.5; font-size: 14px;">{text}</div>'
|
635 |
|
636 |
return html_output
|
637 |
-
|
638 |
def synthesize_audio(text, language):
|
639 |
-
if not TTS_SUPPORT:
|
640 |
return None
|
641 |
|
642 |
try:
|
643 |
-
#
|
644 |
-
|
645 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
646 |
|
647 |
-
|
648 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
649 |
tts.save(tmp_file.name)
|
650 |
-
return tmp_file.name
|
|
|
651 |
except Exception as e:
|
652 |
-
print(f"Audio synthesis failed: {e}")
|
653 |
return None
|
654 |
|
|
|
655 |
def new_chat():
|
656 |
"""Reset all fields for a new chat session"""
|
657 |
return (
|
|
|
634 |
html_output = f'<div style="padding: 10px; line-height: 1.5; font-size: 14px;">{text}</div>'
|
635 |
|
636 |
return html_output
|
|
|
637 |
def synthesize_audio(text, language):
|
638 |
+
if not TTS_SUPPORT or not text:
|
639 |
return None
|
640 |
|
641 |
try:
|
642 |
+
# Map language name to code (e.g., "English" → "en")
|
643 |
+
lang_code = language.lower()[:2] # Simple fallback
|
644 |
+
lang_map = {"english": "en", "spanish": "es", "french": "fr"} # Expand as needed
|
645 |
+
lang_code = lang_map.get(language.lower(), lang_code)
|
646 |
+
|
647 |
+
# Shorten text for gTTS limit
|
648 |
+
audio_text = f"Security alert: {text[:100]}..." if len(text) > 100 else text
|
649 |
+
|
650 |
+
tts = gTTS(text=audio_text, lang=lang_code, slow=False)
|
651 |
|
652 |
+
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as tmp_file:
|
|
|
653 |
tts.save(tmp_file.name)
|
654 |
+
return tmp_file.name # Return full path
|
655 |
+
|
656 |
except Exception as e:
|
657 |
+
print(f"⚠️ Audio synthesis failed: {e}")
|
658 |
return None
|
659 |
|
660 |
+
|
661 |
def new_chat():
|
662 |
"""Reset all fields for a new chat session"""
|
663 |
return (
|