Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve default source behaviour in Audio #6314

Merged
merged 6 commits into from Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/polite-views-wear.md
@@ -0,0 +1,6 @@
---
"@gradio/atoms": patch
"gradio": patch
---

fix:Improve default source behaviour in Audio
4 changes: 2 additions & 2 deletions gradio/components/audio.py
Expand Up @@ -85,7 +85,7 @@ def __init__(
"""
Parameters:
value: A path, URL, or [sample_rate, numpy array] tuple (sample rate in Hz, audio data as a float or int numpy array) for the default value that Audio component is going to take. If callable, the function will be called whenever the app loads to set the initial value of the component.
sources: A list of sources permitted for audio. "upload" creates a box where user can drop an audio file, "microphone" creates a microphone input. If None, defaults to ["upload", "microphone"], or ["microphone"] if `streaming` is True.
sources: A list of sources permitted for audio. "upload" creates a box where user can drop an audio file, "microphone" creates a microphone input. The first element in the list will be used as the default source. If None, defaults to ["upload", "microphone"], or ["microphone"] if `streaming` is True.
type: The format the audio file is converted to before being passed into the prediction function. "numpy" converts the audio to a tuple consisting of: (int sample rate, numpy.array for the data), "filepath" passes a str path to a temporary file containing the audio.
label: The label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
Expand All @@ -107,7 +107,7 @@ def __init__(
max_length: The maximum length of audio (in seconds) that the user can pass into the prediction function. If None, there is no maximum length.
waveform_options: A dictionary of options for the waveform display. Options include: waveform_color (str), waveform_progress_color (str), show_controls (bool), skip_length (int). Default is None, which uses the default values for these options.
"""
valid_sources: list[Literal["upload", "microphone"]] = ["microphone", "upload"]
valid_sources: list[Literal["upload", "microphone"]] = ["upload", "microphone"]

if sources is None:
sources = ["microphone"] if streaming else valid_sources
Expand Down
7 changes: 7 additions & 0 deletions js/atoms/src/SelectSource.svelte
Expand Up @@ -11,6 +11,7 @@
{#if sources.includes("upload")}
<button
class="icon"
class:selected={active_source === "upload"}
aria-label="Upload file"
on:click={() => {
handle_clear();
Expand All @@ -22,6 +23,7 @@
{#if sources.includes("microphone")}
<button
class="icon"
class:selected={active_source === "microphone"}
aria-label="Record audio"
on:click={() => {
handle_clear();
Expand All @@ -33,6 +35,7 @@
{#if sources.includes("webcam")}
<button
class="icon"
class:selected={active_source === "webcam"}
aria-label="Record video"
on:click={() => {
handle_clear();
Expand Down Expand Up @@ -67,6 +70,10 @@
border-radius: var(--radius-md);
}

.selected {
color: var(--color-accent);
}

.icon:hover,
.icon:focus {
color: var(--color-accent);
Expand Down