Skip to content

Commit

Permalink
Allow recording with audio
Browse files Browse the repository at this point in the history
  • Loading branch information
masenf committed Feb 1, 2024
1 parent 6890b65 commit eebd2d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions webcam/webcam/react_webcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Webcam(rx.Component):
is_default = True

screenshot_format: rx.Var[str] = "image/jpeg" # type: ignore
audio: rx.Var[bool]
special_props: set[rx.Var] = [rx.Var.create("muted")]

def _get_hooks(self) -> str | None:
if self.id is not None:
Expand Down
3 changes: 2 additions & 1 deletion webcam/webcam/webcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def on_start_recording(self):
def handle_video_chunk(self, chunk: str):
print("Got video chunk", len(chunk))
with open(self.video_path, "ab") as f:
with urlopen(chunk) as vid:
with urlopen(chunk.replace("codecs=avc1,opus;", "")) as vid:
f.write(vid.read())

def on_stop_recording(self):
Expand Down Expand Up @@ -183,6 +183,7 @@ def webcam_upload_component(ref: str) -> rx.Component:
ref=ref,
handler=State.handle_screenshot, # type: ignore
),
audio=True,
),
rx.cond(
~State.recording,
Expand Down

0 comments on commit eebd2d4

Please sign in to comment.