18
18
from pydantic import ValidationError
19
19
from pydub import AudioSegment
20
20
from streamlit .runtime .scriptrunner import add_script_run_ctx
21
- from streamlit_webrtc import RTCConfiguration , WebRtcMode
21
+ from streamlit_webrtc import WebRtcMode
22
22
23
23
from pyrobbot import GeneralDefinitions
24
24
from pyrobbot .chat_configs import VoiceChatConfigs
25
25
from pyrobbot .general_utils import trim_beginning
26
26
from pyrobbot .openai_utils import OpenAiClientWrapper
27
27
28
28
from .app_page_templates import AppPage , ChatBotPage , _RecoveredChat
29
- from .app_utils import WebAppChat , filter_page_info_from_queue , get_avatar_images
29
+ from .app_utils import (
30
+ WebAppChat ,
31
+ filter_page_info_from_queue ,
32
+ get_avatar_images ,
33
+ get_ice_servers ,
34
+ )
30
35
31
36
incoming_frame_queue = queue .Queue ()
32
37
possible_speech_chunks_queue = queue .Queue ()
@@ -308,6 +313,11 @@ def __init__(self, **kwargs) -> None:
308
313
self .text_prompt_queue = text_prompt_queue
309
314
self .reply_ongoing = reply_ongoing
310
315
316
+ @property
317
+ def ice_servers (self ):
318
+ """Return the ICE servers for WebRTC."""
319
+ return get_ice_servers ()
320
+
311
321
@property
312
322
def continuous_audio_input_engine_is_running (self ):
313
323
"""Return whether the continuous audio input engine is running."""
@@ -318,12 +328,7 @@ def continuous_audio_input_engine_is_running(self):
318
328
)
319
329
320
330
def render_continuous_audio_input_widget (self ):
321
- """Render the continuous audio input widget."""
322
- # Definitions related to webrtc_streamer
323
- rtc_configuration = RTCConfiguration (
324
- {"iceServers" : [{"urls" : ["stun:stun.l.google.com:19302" ]}]}
325
- )
326
-
331
+ """Render the continuous audio input widget using webrtc_streamer."""
327
332
try :
328
333
selected_page = self .selected_page
329
334
except StopIteration :
@@ -377,7 +382,7 @@ def audio_frame_callback(frame):
377
382
self .stream_audio_context = streamlit_webrtc .component .webrtc_streamer (
378
383
key = "sendonly-audio" ,
379
384
mode = WebRtcMode .SENDONLY ,
380
- rtc_configuration = rtc_configuration ,
385
+ rtc_configuration = { "iceServers" : self . ice_servers } ,
381
386
media_stream_constraints = {"audio" : True , "video" : False },
382
387
desired_playing_state = True ,
383
388
audio_frame_callback = audio_frame_callback ,
0 commit comments