Spaces:
Sleeping
Sleeping
Update frontend.py
Browse files- frontend.py +17 -6
frontend.py
CHANGED
@@ -71,7 +71,17 @@ if "enable_audio" not in st.session_state:
|
|
71 |
|
72 |
# Azure TTS function
|
73 |
def azure_speak(text, lang='en-US'):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
try:
|
|
|
75 |
speech_config = speechsdk.SpeechConfig(
|
76 |
subscription=st.secrets["AZURE_SPEECH_KEY"],
|
77 |
region=st.secrets["AZURE_REGION"]
|
@@ -81,17 +91,18 @@ def azure_speak(text, lang='en-US'):
|
|
81 |
audio_config = speechsdk.audio.AudioOutputConfig(filename=tmpfile.name)
|
82 |
synthesizer = speechsdk.SpeechSynthesizer(speech_config, audio_config)
|
83 |
result = synthesizer.speak_text_async(text).get()
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
except Exception as e:
|
91 |
st.error(f"Azure TTS error: {e}")
|
92 |
return None
|
93 |
|
94 |
|
|
|
95 |
tab1, tab2 = st.tabs(["π§ Analyze Review", "π Bulk Reviews"])
|
96 |
|
97 |
# === SINGLE REVIEW ANALYSIS ===
|
|
|
71 |
|
72 |
# Azure TTS function
|
73 |
def azure_speak(text, lang='en-US'):
|
74 |
+
import os
|
75 |
+
if "HF_SPACE_ID" in os.environ:
|
76 |
+
st.warning("Azure TTS is not supported on Hugging Face Spaces. Using fallback TTS.")
|
77 |
+
return None
|
78 |
+
|
79 |
+
if st.session_state.tts_usage_count > 20:
|
80 |
+
st.warning("π TTS usage limit reached.")
|
81 |
+
return None
|
82 |
+
|
83 |
try:
|
84 |
+
import azure.cognitiveservices.speech as speechsdk
|
85 |
speech_config = speechsdk.SpeechConfig(
|
86 |
subscription=st.secrets["AZURE_SPEECH_KEY"],
|
87 |
region=st.secrets["AZURE_REGION"]
|
|
|
91 |
audio_config = speechsdk.audio.AudioOutputConfig(filename=tmpfile.name)
|
92 |
synthesizer = speechsdk.SpeechSynthesizer(speech_config, audio_config)
|
93 |
result = synthesizer.speak_text_async(text).get()
|
94 |
+
if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
|
95 |
+
st.session_state.tts_usage_count += 1
|
96 |
+
return tmpfile.name
|
97 |
+
else:
|
98 |
+
st.error("β Azure TTS failed.")
|
99 |
+
return None
|
100 |
except Exception as e:
|
101 |
st.error(f"Azure TTS error: {e}")
|
102 |
return None
|
103 |
|
104 |
|
105 |
+
|
106 |
tab1, tab2 = st.tabs(["π§ Analyze Review", "π Bulk Reviews"])
|
107 |
|
108 |
# === SINGLE REVIEW ANALYSIS ===
|