streamlit-webrtc 0.62.3__py3-none-any.whl → 0.63.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- streamlit_webrtc/__init__.py +15 -2
- streamlit_webrtc/factory.py +35 -1
- streamlit_webrtc/frontend/dist/assets/{index-DuUNdoqd.js → index-Cn4hJFys.js} +20 -20
- streamlit_webrtc/frontend/dist/index.html +1 -1
- streamlit_webrtc/source.py +61 -0
- {streamlit_webrtc-0.62.3.dist-info → streamlit_webrtc-0.63.0.dist-info}/METADATA +1 -1
- {streamlit_webrtc-0.62.3.dist-info → streamlit_webrtc-0.63.0.dist-info}/RECORD +9 -9
- {streamlit_webrtc-0.62.3.dist-info → streamlit_webrtc-0.63.0.dist-info}/WHEEL +0 -0
- {streamlit_webrtc-0.62.3.dist-info → streamlit_webrtc-0.63.0.dist-info}/licenses/LICENSE +0 -0
streamlit_webrtc/__init__.py
CHANGED
@@ -21,9 +21,19 @@ from .credentials import (
|
|
21
21
|
get_hf_ice_servers,
|
22
22
|
get_twilio_ice_servers,
|
23
23
|
)
|
24
|
-
from .factory import
|
24
|
+
from .factory import (
|
25
|
+
create_audio_source_track,
|
26
|
+
create_mix_track,
|
27
|
+
create_process_track,
|
28
|
+
create_video_source_track,
|
29
|
+
)
|
25
30
|
from .mix import MediaStreamMixTrack, MixerCallback
|
26
|
-
from .source import
|
31
|
+
from .source import (
|
32
|
+
AudioSourceCallback,
|
33
|
+
AudioSourceTrack,
|
34
|
+
VideoSourceCallback,
|
35
|
+
VideoSourceTrack,
|
36
|
+
)
|
27
37
|
from .webrtc import (
|
28
38
|
AudioProcessorBase,
|
29
39
|
AudioProcessorFactory,
|
@@ -64,7 +74,10 @@ __all__ = [
|
|
64
74
|
"VideoReceiver",
|
65
75
|
"VideoSourceTrack",
|
66
76
|
"VideoSourceCallback",
|
77
|
+
"AudioSourceTrack",
|
78
|
+
"AudioSourceCallback",
|
67
79
|
"create_video_source_track",
|
80
|
+
"create_audio_source_track",
|
68
81
|
"WebRtcMode",
|
69
82
|
"WebRtcWorker",
|
70
83
|
"MediaStreamConstraints",
|
streamlit_webrtc/factory.py
CHANGED
@@ -25,7 +25,12 @@ from .process import (
|
|
25
25
|
VideoProcessTrack,
|
26
26
|
)
|
27
27
|
from .relay import get_global_relay
|
28
|
-
from .source import
|
28
|
+
from .source import (
|
29
|
+
AudioSourceCallback,
|
30
|
+
AudioSourceTrack,
|
31
|
+
VideoSourceCallback,
|
32
|
+
VideoSourceTrack,
|
33
|
+
)
|
29
34
|
|
30
35
|
_PROCESSOR_TRACK_CACHE_KEY_PREFIX = "__PROCESSOR_TRACK_CACHE__"
|
31
36
|
|
@@ -204,3 +209,32 @@ def create_video_source_track(
|
|
204
209
|
video_source_track = VideoSourceTrack(callback=callback, fps=fps)
|
205
210
|
st.session_state[cache_key] = video_source_track
|
206
211
|
return video_source_track
|
212
|
+
|
213
|
+
|
214
|
+
_AUDIO_SOURCE_TRACK_CACHE_KEY_PREFIX = "__AUDIO_SOURCE_TRACK_CACHE__"
|
215
|
+
|
216
|
+
|
217
|
+
def create_audio_source_track(
|
218
|
+
callback: AudioSourceCallback,
|
219
|
+
key: str,
|
220
|
+
sample_rate: int = 48000,
|
221
|
+
ptime: float = 0.020,
|
222
|
+
) -> AudioSourceTrack:
|
223
|
+
cache_key = _AUDIO_SOURCE_TRACK_CACHE_KEY_PREFIX + key
|
224
|
+
if (
|
225
|
+
cache_key in st.session_state
|
226
|
+
and isinstance(st.session_state[cache_key], AudioSourceTrack)
|
227
|
+
and st.session_state[cache_key].kind == "audio"
|
228
|
+
and st.session_state[cache_key].readyState == "live"
|
229
|
+
):
|
230
|
+
audio_source_track: AudioSourceTrack = st.session_state[cache_key]
|
231
|
+
audio_source_track._callback = callback
|
232
|
+
audio_source_track._sample_rate = sample_rate
|
233
|
+
audio_source_track._ptime = ptime
|
234
|
+
audio_source_track._samples_per_frame = int(sample_rate * ptime)
|
235
|
+
else:
|
236
|
+
audio_source_track = AudioSourceTrack(
|
237
|
+
callback=callback, sample_rate=sample_rate, ptime=ptime
|
238
|
+
)
|
239
|
+
st.session_state[cache_key] = audio_source_track
|
240
|
+
return audio_source_track
|