Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -779,6 +779,30 @@ else:
|
|
| 779 |
st.session_state["recording_complete"] = False
|
| 780 |
st.rerun()
|
| 781 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 782 |
# === Main QA Interface ===
|
| 783 |
if st.session_state["generated_questions"]:
|
| 784 |
idx = st.session_state["current_question_index"]
|
|
@@ -847,11 +871,7 @@ if st.session_state["generated_questions"]:
|
|
| 847 |
mode=WebRtcMode.SENDONLY,
|
| 848 |
audio_receiver_size=256,
|
| 849 |
media_stream_constraints={"audio": True, "video": False},
|
| 850 |
-
rtc_configuration
|
| 851 |
-
"iceServers": [
|
| 852 |
-
{"urls": ["stun:stun.l.google.com:19302"] }
|
| 853 |
-
]
|
| 854 |
-
}
|
| 855 |
)
|
| 856 |
|
| 857 |
if webrtc_ctx.state.playing:
|
|
|
|
| 779 |
st.session_state["recording_complete"] = False
|
| 780 |
st.rerun()
|
| 781 |
|
| 782 |
+
def get_ice_servers():
|
| 783 |
+
"""Use Twilio's TURN server because Streamlit Community Cloud has changed
|
| 784 |
+
its infrastructure and WebRTC connection cannot be established without TURN server now. # noqa: E501
|
| 785 |
+
We considered Open Relay Project (https://www.metered.ca/tools/openrelay/) too,
|
| 786 |
+
but it is not stable and hardly works as some people reported like https://github.com/aiortc/aiortc/issues/832#issuecomment-1482420656 # noqa: E501
|
| 787 |
+
See https://github.com/whitphx/streamlit-webrtc/issues/1213
|
| 788 |
+
"""
|
| 789 |
+
|
| 790 |
+
# Ref: https://www.twilio.com/docs/stun-turn/api
|
| 791 |
+
try:
|
| 792 |
+
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
|
| 793 |
+
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
|
| 794 |
+
except KeyError:
|
| 795 |
+
logger.warning(
|
| 796 |
+
"Twilio credentials are not set. Fallback to a free STUN server from Google." # noqa: E501
|
| 797 |
+
)
|
| 798 |
+
return [{"urls": ["stun:stun.l.google.com:19302"]}]
|
| 799 |
+
|
| 800 |
+
client = Client(account_sid, auth_token)
|
| 801 |
+
|
| 802 |
+
token = client.tokens.create()
|
| 803 |
+
|
| 804 |
+
return token.ice_servers
|
| 805 |
+
|
| 806 |
# === Main QA Interface ===
|
| 807 |
if st.session_state["generated_questions"]:
|
| 808 |
idx = st.session_state["current_question_index"]
|
|
|
|
| 871 |
mode=WebRtcMode.SENDONLY,
|
| 872 |
audio_receiver_size=256,
|
| 873 |
media_stream_constraints={"audio": True, "video": False},
|
| 874 |
+
rtc_configuration={"iceServers": get_ice_servers()},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 875 |
)
|
| 876 |
|
| 877 |
if webrtc_ctx.state.playing:
|