mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-05 18:09:23 +08:00
chore: dispatch starting_recording and stop_recording. (#342)
Co-authored-by: Ming Xu <albertxu@amazon.com>
This commit is contained in:
@@ -57,7 +57,7 @@ class WebRTC(Component, WebRTCConnectionMixin):
|
|||||||
Demos: video_identity_2
|
Demos: video_identity_2
|
||||||
"""
|
"""
|
||||||
|
|
||||||
EVENTS = ["tick", "state_change", "submit"]
|
EVENTS = ["tick", "state_change", "submit", "start_recording", "stop_recording"]
|
||||||
data_model = WebRTCModel
|
data_model = WebRTCModel
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|||||||
@@ -208,6 +208,8 @@
|
|||||||
{pulse_color}
|
{pulse_color}
|
||||||
{button_labels}
|
{button_labels}
|
||||||
{variant}
|
{variant}
|
||||||
|
on:start_recording={() => gradio.dispatch("start_recording")}
|
||||||
|
on:stop_recording={() => gradio.dispatch("stop_recording")}
|
||||||
on:tick={() => gradio.dispatch("tick")}
|
on:tick={() => gradio.dispatch("tick")}
|
||||||
on:error={({ detail }) => gradio.dispatch("error", detail)}
|
on:error={({ detail }) => gradio.dispatch("error", detail)}
|
||||||
on:warning={({ detail }) => gradio.dispatch("warning", detail)}
|
on:warning={({ detail }) => gradio.dispatch("warning", detail)}
|
||||||
|
|||||||
@@ -104,6 +104,8 @@
|
|||||||
error: string;
|
error: string;
|
||||||
play: undefined;
|
play: undefined;
|
||||||
stop: undefined;
|
stop: undefined;
|
||||||
|
start_recording: undefined;
|
||||||
|
stop_recording: undefined;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
async function access_mic(): Promise<void> {
|
async function access_mic(): Promise<void> {
|
||||||
@@ -147,6 +149,7 @@
|
|||||||
|
|
||||||
async function start_stream(): Promise<void> {
|
async function start_stream(): Promise<void> {
|
||||||
if (stream_state === "open") {
|
if (stream_state === "open") {
|
||||||
|
dispatch("stop_recording");
|
||||||
stop(pc);
|
stop(pc);
|
||||||
stream_state = "closed";
|
stream_state = "closed";
|
||||||
_time_limit = null;
|
_time_limit = null;
|
||||||
@@ -154,6 +157,8 @@
|
|||||||
await server.quit_output_stream({ webrtc_id: _webrtc_id });
|
await server.quit_output_stream({ webrtc_id: _webrtc_id });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispatch("start_recording");
|
||||||
_webrtc_id = Math.random().toString(36).substring(2);
|
_webrtc_id = Math.random().toString(36).substring(2);
|
||||||
value.webrtc_id = _webrtc_id;
|
value.webrtc_id = _webrtc_id;
|
||||||
stream_state = "waiting";
|
stream_state = "waiting";
|
||||||
@@ -325,6 +330,8 @@
|
|||||||
bind:this={audio_player}
|
bind:this={audio_player}
|
||||||
on:ended={() => dispatch("stop")}
|
on:ended={() => dispatch("stop")}
|
||||||
on:play={() => dispatch("play")}
|
on:play={() => dispatch("play")}
|
||||||
|
on:start_recording
|
||||||
|
on:stop_recording
|
||||||
/>
|
/>
|
||||||
{#if variant === "textbox"}
|
{#if variant === "textbox"}
|
||||||
<TextboxWithMic
|
<TextboxWithMic
|
||||||
|
|||||||
@@ -146,6 +146,7 @@
|
|||||||
|
|
||||||
async function start_webrtc(): Promise<void> {
|
async function start_webrtc(): Promise<void> {
|
||||||
if (stream_state === "closed") {
|
if (stream_state === "closed") {
|
||||||
|
dispatch("start_recording");
|
||||||
await server.turn().then((rtc_configuration_) => {
|
await server.turn().then((rtc_configuration_) => {
|
||||||
if (rtc_configuration_.error) {
|
if (rtc_configuration_.error) {
|
||||||
dispatch("error", rtc_configuration_.error);
|
dispatch("error", rtc_configuration_.error);
|
||||||
@@ -207,6 +208,7 @@
|
|||||||
stream_state = "closed";
|
stream_state = "closed";
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
dispatch("stop_recording");
|
||||||
stop(pc);
|
stop(pc);
|
||||||
stream_state = "closed";
|
stream_state = "closed";
|
||||||
_time_limit = null;
|
_time_limit = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user