Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -816,9 +816,16 @@ def get_ice_servers():
|
|
| 816 |
|
| 817 |
return token.ice_servers
|
| 818 |
|
| 819 |
-
# Function to generate question audio
|
| 820 |
-
async def generate_question_audio(question):
|
| 821 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 822 |
|
| 823 |
@st.cache_data(show_spinner=False)
|
| 824 |
def get_cached_question_audio(question_text):
|
|
@@ -842,15 +849,25 @@ if st.session_state["generated_questions"]:
|
|
| 842 |
})
|
| 843 |
"""
|
| 844 |
if not st.session_state.get("question_played"):
|
| 845 |
-
st.session_state["question_audio_file"] =
|
| 846 |
st.session_state.update({
|
| 847 |
"question_played": True,
|
| 848 |
"question_start_time": time.time(),
|
| 849 |
"record_phase": "audio_playing",
|
| 850 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 851 |
|
| 852 |
st.markdown(f"**Q{idx + 1}:** {question}")
|
| 853 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 854 |
|
| 855 |
now = time.time()
|
| 856 |
elapsed = now - st.session_state.get("question_start_time", 0)
|
|
|
|
| 816 |
|
| 817 |
return token.ice_servers
|
| 818 |
|
| 819 |
+
# Function to generate question audio and save to a valid path
|
| 820 |
+
async def generate_question_audio(question, voice="en-IE-EmilyNeural"):
|
| 821 |
+
clean_question = question.strip().replace("\n", " ")
|
| 822 |
+
tts = edge_tts.Communicate(text=clean_question, voice=voice)
|
| 823 |
+
|
| 824 |
+
|
| 825 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3", dir=os.getcwd()) as tmp_file:
|
| 826 |
+
output_path = tmp_file.name
|
| 827 |
+
await tts.save(output_path)
|
| 828 |
+
return output_path
|
| 829 |
|
| 830 |
@st.cache_data(show_spinner=False)
|
| 831 |
def get_cached_question_audio(question_text):
|
|
|
|
| 849 |
})
|
| 850 |
"""
|
| 851 |
if not st.session_state.get("question_played"):
|
| 852 |
+
st.session_state["question_audio_file"] = asyncio.run(generate_question_audio(question))
|
| 853 |
st.session_state.update({
|
| 854 |
"question_played": True,
|
| 855 |
"question_start_time": time.time(),
|
| 856 |
"record_phase": "audio_playing",
|
| 857 |
})
|
| 858 |
+
|
| 859 |
+
|
| 860 |
+
#st.markdown(f"**Q{idx + 1}:** {question}")
|
| 861 |
+
#st.audio(st.session_state["question_audio_file"], format="audio/mp3")
|
| 862 |
|
| 863 |
st.markdown(f"**Q{idx + 1}:** {question}")
|
| 864 |
+
audio_file = st.session_state["question_audio_file"]
|
| 865 |
+
if os.path.exists(audio_file) and os.path.getsize(audio_file) > 0:
|
| 866 |
+
st.audio(audio_file, format="audio/mp3")
|
| 867 |
+
else:
|
| 868 |
+
st.warning("⚠️ Could not load question audio. Please retry.")
|
| 869 |
+
|
| 870 |
+
|
| 871 |
|
| 872 |
now = time.time()
|
| 873 |
elapsed = now - st.session_state.get("question_start_time", 0)
|