mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-05 18:09:23 +08:00
音频配置参数引入
This commit is contained in:
16
demo/app.py
16
demo/app.py
@@ -97,6 +97,22 @@ with gr.Blocks(css=css) as demo:
|
|||||||
mode="send-receive",
|
mode="send-receive",
|
||||||
video_chat=True,
|
video_chat=True,
|
||||||
elem_id="video-source",
|
elem_id="video-source",
|
||||||
|
track_constraints={
|
||||||
|
"video": {
|
||||||
|
"facingMode": "user",
|
||||||
|
"width": {"ideal": 500},
|
||||||
|
"height": {"ideal": 500},
|
||||||
|
"frameRate": {"ideal": 30},
|
||||||
|
},
|
||||||
|
"audio": {
|
||||||
|
"echoCancellation": True,
|
||||||
|
"noiseSuppression": {"exact": True},
|
||||||
|
"autoGainControl": {"exact": False},
|
||||||
|
"sampleRate": {"ideal": 24000},
|
||||||
|
"sampleSize": {"ideal": 16},
|
||||||
|
"channelCount": {"exact": 1},
|
||||||
|
},
|
||||||
|
}
|
||||||
)
|
)
|
||||||
webrtc.stream(
|
webrtc.stream(
|
||||||
VideoChatHandler(),
|
VideoChatHandler(),
|
||||||
|
|||||||
BIN
dist/gradio_webrtc-0.0.30.dev0-py3-none-any.whl
vendored
BIN
dist/gradio_webrtc-0.0.30.dev0-py3-none-any.whl
vendored
Binary file not shown.
@@ -81,6 +81,7 @@
|
|||||||
on:error={({ detail }) => gradio.dispatch("error", detail)}
|
on:error={({ detail }) => gradio.dispatch("error", detail)}
|
||||||
i18n={gradio.i18n}
|
i18n={gradio.i18n}
|
||||||
stream_handler={(...args) => gradio.client.stream(...args)}
|
stream_handler={(...args) => gradio.client.stream(...args)}
|
||||||
|
{track_constraints}
|
||||||
{height}
|
{height}
|
||||||
{on_change_cb} {rtc_configuration}
|
{on_change_cb} {rtc_configuration}
|
||||||
on:tick={() => gradio.dispatch("tick")}
|
on:tick={() => gradio.dispatch("tick")}
|
||||||
|
|||||||
@@ -19,18 +19,30 @@ export async function get_video_stream(
|
|||||||
include_audio: boolean | { deviceId: { exact: string } },
|
include_audio: boolean | { deviceId: { exact: string } },
|
||||||
video_source: HTMLVideoElement,
|
video_source: HTMLVideoElement,
|
||||||
device_id?: string,
|
device_id?: string,
|
||||||
track_constraints?: MediaTrackConstraints
|
track_constraints?:
|
||||||
|
| MediaTrackConstraints
|
||||||
|
| { video: MediaTrackConstraints; audio: MediaTrackConstraints }
|
||||||
): Promise<MediaStream> {
|
): Promise<MediaStream> {
|
||||||
const fallback_constraints = track_constraints || {
|
console.log(track_constraints);
|
||||||
width: { ideal: 500 },
|
const video_fallback_constraints = (track_constraints as any)?.video ||
|
||||||
height: { ideal: 500 },
|
track_constraints || {
|
||||||
};
|
width: { ideal: 500 },
|
||||||
|
height: { ideal: 500 },
|
||||||
|
};
|
||||||
|
const audio_fallback_constraints = (track_constraints as any)?.audio ||
|
||||||
|
track_constraints || {
|
||||||
|
echoCancellation: true,
|
||||||
|
noiseSuppression: true,
|
||||||
|
autoGainControl: true,
|
||||||
|
};
|
||||||
const constraints = {
|
const constraints = {
|
||||||
video: device_id
|
video: device_id
|
||||||
? { deviceId: { exact: device_id }, ...fallback_constraints }
|
? { deviceId: { exact: device_id }, ...video_fallback_constraints }
|
||||||
: fallback_constraints,
|
: video_fallback_constraints,
|
||||||
audio: include_audio,
|
audio:
|
||||||
|
typeof include_audio === "object"
|
||||||
|
? { ...include_audio, ...audio_fallback_constraints }
|
||||||
|
: include_audio,
|
||||||
};
|
};
|
||||||
|
|
||||||
return navigator.mediaDevices
|
return navigator.mediaDevices
|
||||||
|
|||||||
Reference in New Issue
Block a user