mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-31 12:20:26 +08:00
Add editable
parameter to Audio (#6745)
* add editable param to audio and add story * add changeset * fix test * fix test again * tweak --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
parent
21ce721bbd
commit
3240d042e9
6
.changeset/breezy-cougars-flow.md
Normal file
6
.changeset/breezy-cougars-flow.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
"@gradio/audio": minor
|
||||
"gradio": minor
|
||||
---
|
||||
|
||||
feat:Add `editable` parameter to Audio
|
@ -82,6 +82,7 @@ class Audio(
|
||||
autoplay: bool = False,
|
||||
show_download_button=True,
|
||||
show_share_button: bool | None = None,
|
||||
editable: bool = True,
|
||||
min_length: int | None = None,
|
||||
max_length: int | None = None,
|
||||
waveform_options: WaveformOptions | dict | None = None,
|
||||
@ -97,7 +98,7 @@ class Audio(
|
||||
container: If True, will place the component in a container - providing some extra padding around the border.
|
||||
scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.
|
||||
min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
|
||||
interactive: if True, will allow users to upload and edit a audio file; if False, can only be used to play audio. If not provided, this is inferred based on whether the component is used as an input or output.
|
||||
interactive: If True, will allow users to upload and edit an audio file. If False, can only be used to play audio. If not provided, this is inferred based on whether the component is used as an input or output.
|
||||
visible: If False, component will be hidden.
|
||||
streaming: If set to True when used in a `live` interface as an input, will automatically stream webcam feed. When used set as an output, takes audio chunks yield from the backend and combines them into one streaming audio output.
|
||||
elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
|
||||
@ -107,6 +108,7 @@ class Audio(
|
||||
autoplay: Whether to automatically play the audio when the component is used as an output. Note: browsers will not autoplay audio files if the user has not interacted with the page yet.
|
||||
show_download_button: If True, will show a download button in the corner of the component for saving audio. If False, icon does not appear.
|
||||
show_share_button: If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise.
|
||||
editable: If True, allows users to manipulate the audio file (if the component is interactive).
|
||||
min_length: The minimum length of audio (in seconds) that the user can pass into the prediction function. If None, there is no minimum length.
|
||||
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.
|
||||
@ -146,6 +148,7 @@ class Audio(
|
||||
if show_share_button is None
|
||||
else show_share_button
|
||||
)
|
||||
self.editable = editable
|
||||
if waveform_options is None:
|
||||
self.waveform_options = WaveformOptions()
|
||||
self.waveform_options = (
|
||||
|
@ -56,6 +56,21 @@
|
||||
}}
|
||||
/>
|
||||
|
||||
<Story
|
||||
name="with disabled editing"
|
||||
args={{
|
||||
value: {
|
||||
path: "https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3",
|
||||
url: "https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3",
|
||||
orig_name: "sample-0.mp3"
|
||||
},
|
||||
interactive: true,
|
||||
sources: ["microphone", "upload"],
|
||||
label: "Audio Upload",
|
||||
editable: false
|
||||
}}
|
||||
/>
|
||||
|
||||
<Story
|
||||
name="with hidden recording waveform"
|
||||
args={{
|
||||
|
@ -34,6 +34,7 @@
|
||||
export let autoplay = false;
|
||||
export let show_download_button = true;
|
||||
export let show_share_button = false;
|
||||
export let editable = true;
|
||||
export let waveform_options: WaveformOptions = {};
|
||||
export let pending: boolean;
|
||||
export let streaming: boolean;
|
||||
@ -190,6 +191,7 @@
|
||||
{pending}
|
||||
{streaming}
|
||||
{handle_reset_value}
|
||||
{editable}
|
||||
bind:dragging
|
||||
on:edit={() => gradio.dispatch("edit")}
|
||||
on:play={() => gradio.dispatch("play")}
|
||||
|
@ -31,6 +31,7 @@
|
||||
export let dragging: boolean;
|
||||
export let active_source: "microphone" | "upload";
|
||||
export let handle_reset_value: () => void = () => {};
|
||||
export let editable = true;
|
||||
|
||||
$: dispatch("drag", dragging);
|
||||
|
||||
@ -259,6 +260,7 @@
|
||||
{waveform_options}
|
||||
{trim_region_settings}
|
||||
{handle_reset_value}
|
||||
{editable}
|
||||
interactive
|
||||
on:stop
|
||||
on:play
|
||||
|
@ -20,6 +20,7 @@
|
||||
event: "stream" | "change" | "stop_recording"
|
||||
) => Promise<void> = () => Promise.resolve();
|
||||
export let interactive = false;
|
||||
export let editable = true;
|
||||
export let trim_region_settings = {};
|
||||
export let waveform_settings: Record<string, any>;
|
||||
export let waveform_options: WaveformOptions;
|
||||
@ -184,6 +185,7 @@
|
||||
{handle_reset_value}
|
||||
{waveform_options}
|
||||
{trim_region_settings}
|
||||
{editable}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
|
@ -23,6 +23,7 @@
|
||||
export let waveform_options: WaveformOptions = {};
|
||||
export let trim_region_settings: WaveformOptions = {};
|
||||
export let show_volume_slider = false;
|
||||
export let editable = true;
|
||||
|
||||
export let trimDuration = 0;
|
||||
|
||||
@ -237,21 +238,21 @@
|
||||
</div>
|
||||
|
||||
<div class="settings-wrapper">
|
||||
{#if showRedo && mode === ""}
|
||||
<button
|
||||
class="action icon"
|
||||
aria-label="Reset audio"
|
||||
on:click={() => {
|
||||
handle_reset_value();
|
||||
clearRegions();
|
||||
mode = "";
|
||||
}}
|
||||
>
|
||||
<Undo />
|
||||
</button>
|
||||
{/if}
|
||||
{#if editable && interactive}
|
||||
{#if showRedo && mode === ""}
|
||||
<button
|
||||
class="action icon"
|
||||
aria-label="Reset audio"
|
||||
on:click={() => {
|
||||
handle_reset_value();
|
||||
clearRegions();
|
||||
mode = "";
|
||||
}}
|
||||
>
|
||||
<Undo />
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
{#if interactive}
|
||||
{#if mode === ""}
|
||||
<button
|
||||
class="action icon"
|
||||
|
@ -731,6 +731,7 @@ class TestAudio:
|
||||
"show_label": True,
|
||||
"label": "Upload Your Audio",
|
||||
"container": True,
|
||||
"editable": True,
|
||||
"min_width": 160,
|
||||
"scale": None,
|
||||
"elem_id": None,
|
||||
@ -776,6 +777,7 @@ class TestAudio:
|
||||
"max_length": None,
|
||||
"min_length": None,
|
||||
"container": True,
|
||||
"editable": True,
|
||||
"min_width": 160,
|
||||
"scale": None,
|
||||
"elem_id": None,
|
||||
|
Loading…
x
Reference in New Issue
Block a user