Hasitha16 commited on
Commit
5094d9c
Β·
verified Β·
1 Parent(s): 9493796

Update frontend.py

Browse files
Files changed (1) hide show
  1. 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
- if result.reason == speechsdk.ResultReason.SynthesizingAudioCompleted:
85
- st.session_state.tts_usage_count += 1
86
- return tmpfile.name
87
- else:
88
- st.error("Speech synthesis failed.")
89
- return None
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 ===