Spaces:
Runtime error
Runtime error
get access to the image frames
Browse files
app.py
CHANGED
@@ -60,14 +60,24 @@ def do_work(data: bytearray) -> tuple[str, bool]:
|
|
60 |
return text, speaker_finished
|
61 |
|
62 |
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
async def queued_audio_frames_callback(
|
67 |
frames: List[av.AudioFrame],
|
68 |
) -> av.AudioFrame:
|
69 |
-
with
|
70 |
-
|
71 |
|
72 |
# create frames to be returned.
|
73 |
new_frames = []
|
@@ -88,8 +98,8 @@ webrtc_ctx = webrtc_streamer(
|
|
88 |
key="charles",
|
89 |
desired_playing_state=playing,
|
90 |
# audio_receiver_size=4096,
|
91 |
-
# audio_frame_callback=process_audio,
|
92 |
queued_audio_frames_callback=queued_audio_frames_callback,
|
|
|
93 |
mode=WebRtcMode.SENDRECV,
|
94 |
rtc_configuration={"iceServers": get_ice_servers()},
|
95 |
async_processing=True,
|
@@ -109,10 +119,18 @@ system_one_audio_history_output = st.empty()
|
|
109 |
sound_chunk = pydub.AudioSegment.empty()
|
110 |
while True:
|
111 |
if webrtc_ctx.state.playing:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
audio_frames = []
|
113 |
-
with
|
114 |
-
while len(
|
115 |
-
frame =
|
116 |
audio_frames.append(frame)
|
117 |
|
118 |
if len(audio_frames) == 0:
|
|
|
60 |
return text, speaker_finished
|
61 |
|
62 |
|
63 |
+
audio_frames_deque_lock = threading.Lock()
|
64 |
+
audio_frames_deque: deque = deque([])
|
65 |
+
|
66 |
+
video_frames_deque_lock = threading.Lock()
|
67 |
+
video_frames_deque: deque = deque([])
|
68 |
+
|
69 |
+
async def queued_video_frames_callback(
|
70 |
+
frames: List[av.AudioFrame],
|
71 |
+
) -> av.AudioFrame:
|
72 |
+
with video_frames_deque_lock:
|
73 |
+
video_frames_deque.extend(frames)
|
74 |
+
return frames
|
75 |
|
76 |
async def queued_audio_frames_callback(
|
77 |
frames: List[av.AudioFrame],
|
78 |
) -> av.AudioFrame:
|
79 |
+
with audio_frames_deque_lock:
|
80 |
+
audio_frames_deque.extend(frames)
|
81 |
|
82 |
# create frames to be returned.
|
83 |
new_frames = []
|
|
|
98 |
key="charles",
|
99 |
desired_playing_state=playing,
|
100 |
# audio_receiver_size=4096,
|
|
|
101 |
queued_audio_frames_callback=queued_audio_frames_callback,
|
102 |
+
queued_video_frames_callback=queued_video_frames_callback,
|
103 |
mode=WebRtcMode.SENDRECV,
|
104 |
rtc_configuration={"iceServers": get_ice_servers()},
|
105 |
async_processing=True,
|
|
|
119 |
sound_chunk = pydub.AudioSegment.empty()
|
120 |
while True:
|
121 |
if webrtc_ctx.state.playing:
|
122 |
+
# handle video
|
123 |
+
video_frames = []
|
124 |
+
with video_frames_deque_lock:
|
125 |
+
while len(video_frames_deque) > 0:
|
126 |
+
frame = video_frames_deque.popleft()
|
127 |
+
video_frames.append(frame)
|
128 |
+
|
129 |
+
# handle audio
|
130 |
audio_frames = []
|
131 |
+
with audio_frames_deque_lock:
|
132 |
+
while len(audio_frames_deque) > 0:
|
133 |
+
frame = audio_frames_deque.popleft()
|
134 |
audio_frames.append(frame)
|
135 |
|
136 |
if len(audio_frames) == 0:
|