gradio-pr-bot commited on
Commit
fa3c160
·
verified ·
1 Parent(s): 8f98dcc

Upload folder using huggingface_hub

Browse files
6.1.0/audio/Index.svelte CHANGED
@@ -147,6 +147,7 @@
147
  waveform_options={gradio.props.waveform_options}
148
  editable={gradio.props.editable}
149
  {minimal}
 
150
  on:share={(e) => gradio.dispatch("share", e.detail)}
151
  on:error={(e) => gradio.dispatch("error", e.detail)}
152
  on:play={() => gradio.dispatch("play")}
@@ -201,6 +202,7 @@
201
  {handle_reset_value}
202
  editable={gradio.props.editable}
203
  bind:dragging
 
204
  on:edit={() => gradio.dispatch("edit")}
205
  on:play={() => gradio.dispatch("play")}
206
  on:pause={() => gradio.dispatch("pause")}
 
147
  waveform_options={gradio.props.waveform_options}
148
  editable={gradio.props.editable}
149
  {minimal}
150
+ bind:playback_position={gradio.props.playback_position}
151
  on:share={(e) => gradio.dispatch("share", e.detail)}
152
  on:error={(e) => gradio.dispatch("error", e.detail)}
153
  on:play={() => gradio.dispatch("play")}
 
202
  {handle_reset_value}
203
  editable={gradio.props.editable}
204
  bind:dragging
205
+ bind:playback_position={gradio.props.playback_position}
206
  on:edit={() => gradio.dispatch("edit")}
207
  on:play={() => gradio.dispatch("play")}
208
  on:pause={() => gradio.dispatch("pause")}
6.1.0/audio/interactive/InteractiveAudio.svelte CHANGED
@@ -47,6 +47,7 @@
47
  export let class_name = "";
48
  export let upload_promise: Promise<any> | null = null;
49
  export let initial_value: FileData | null = null;
 
50
 
51
  export let time_limit: number | null = null;
52
  export let stream_state: "open" | "waiting" | "closed" = "closed";
@@ -314,6 +315,7 @@
314
  {handle_reset_value}
315
  {editable}
316
  {loop}
 
317
  interactive
318
  on:stop
319
  on:play
 
47
  export let class_name = "";
48
  export let upload_promise: Promise<any> | null = null;
49
  export let initial_value: FileData | null = null;
50
+ export let playback_position = 0;
51
 
52
  export let time_limit: number | null = null;
53
  export let stream_state: "open" | "waiting" | "closed" = "closed";
 
315
  {handle_reset_value}
316
  {editable}
317
  {loop}
318
+ bind:playback_position
319
  interactive
320
  on:stop
321
  on:play
6.1.0/audio/package.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "@gradio/audio",
3
- "version": "0.20.0",
4
  "description": "Gradio UI packages",
5
  "type": "module",
6
  "author": "",
 
1
  {
2
  "name": "@gradio/audio",
3
+ "version": "0.21.0",
4
  "description": "Gradio UI packages",
5
  "type": "module",
6
  "author": "",
6.1.0/audio/player/AudioPlayer.svelte CHANGED
@@ -29,9 +29,12 @@
29
  export let mode = "";
30
  export let loop: boolean;
31
  export let handle_reset_value: () => void = () => {};
 
 
32
 
33
  let container: HTMLDivElement;
34
  let waveform: WaveSurfer | undefined;
 
35
  let waveform_component_wrapper: HTMLDivElement;
36
  let playing = false;
37
 
@@ -62,6 +65,15 @@
62
  $: use_waveform =
63
  waveform_options.show_recording_waveform && !value?.is_stream;
64
 
 
 
 
 
 
 
 
 
 
65
  const create_waveform = (): void => {
66
  waveform = WaveSurfer.create({
67
  container: container,
@@ -85,18 +97,24 @@
85
  durationRef && (durationRef.textContent = format_time(duration));
86
  });
87
 
88
- waveform?.on(
89
- "timeupdate",
90
- (currentTime: any) =>
91
- timeRef && (timeRef.textContent = format_time(currentTime))
92
- );
 
 
 
 
93
 
94
  waveform?.on("interaction", () => {
95
  const currentTime = waveform?.getCurrentTime() || 0;
96
  timeRef && (timeRef.textContent = format_time(currentTime));
 
97
  });
98
 
99
  waveform?.on("ready", () => {
 
100
  if (!waveform_settings.autoplay) {
101
  waveform?.stop();
102
  } else {
@@ -341,7 +359,8 @@
341
  on:ended={() => dispatch("stop")}
342
  on:play={() => dispatch("play")}
343
  preload="metadata"
344
- />
 
345
  {#if value === null}
346
  <Empty size="small">
347
  <Music />
 
29
  export let mode = "";
30
  export let loop: boolean;
31
  export let handle_reset_value: () => void = () => {};
32
+ export let playback_position = 0;
33
+ let old_playback_position = 0;
34
 
35
  let container: HTMLDivElement;
36
  let waveform: WaveSurfer | undefined;
37
+ let waveform_ready = false;
38
  let waveform_component_wrapper: HTMLDivElement;
39
  let playing = false;
40
 
 
65
  $: use_waveform =
66
  waveform_options.show_recording_waveform && !value?.is_stream;
67
 
68
+ $: if (
69
+ waveform_ready &&
70
+ old_playback_position !== playback_position &&
71
+ audio_duration
72
+ ) {
73
+ waveform?.seekTo(playback_position / audio_duration);
74
+ old_playback_position = playback_position;
75
+ }
76
+
77
  const create_waveform = (): void => {
78
  waveform = WaveSurfer.create({
79
  container: container,
 
97
  durationRef && (durationRef.textContent = format_time(duration));
98
  });
99
 
100
+ let firstTimeUpdate = true;
101
+ waveform?.on("timeupdate", (currentTime: any) => {
102
+ timeRef && (timeRef.textContent = format_time(currentTime));
103
+ if (firstTimeUpdate) {
104
+ firstTimeUpdate = false;
105
+ return;
106
+ }
107
+ old_playback_position = playback_position = currentTime;
108
+ });
109
 
110
  waveform?.on("interaction", () => {
111
  const currentTime = waveform?.getCurrentTime() || 0;
112
  timeRef && (timeRef.textContent = format_time(currentTime));
113
+ old_playback_position = playback_position = currentTime;
114
  });
115
 
116
  waveform?.on("ready", () => {
117
+ waveform_ready = true;
118
  if (!waveform_settings.autoplay) {
119
  waveform?.stop();
120
  } else {
 
359
  on:ended={() => dispatch("stop")}
360
  on:play={() => dispatch("play")}
361
  preload="metadata"
362
+ >
363
+ </audio>
364
  {#if value === null}
365
  <Empty size="small">
366
  <Music />
6.1.0/audio/shared/types.ts CHANGED
@@ -36,6 +36,7 @@ export interface AudioProps {
36
  stream_every: number;
37
  input_ready: boolean;
38
  minimal?: boolean;
 
39
  }
40
 
41
  export interface AudioEvents {
 
36
  stream_every: number;
37
  input_ready: boolean;
38
  minimal?: boolean;
39
+ playback_position: number;
40
  }
41
 
42
  export interface AudioEvents {
6.1.0/audio/static/StaticAudio.svelte CHANGED
@@ -30,6 +30,7 @@
30
  export let loop: boolean;
31
  export let display_icon_button_wrapper_top_corner = false;
32
  export let minimal = false;
 
33
 
34
  const dispatch = createEventDispatcher<{
35
  change: FileData;
@@ -90,6 +91,7 @@
90
  {waveform_options}
91
  {editable}
92
  {loop}
 
93
  on:pause
94
  on:play
95
  on:stop
 
30
  export let loop: boolean;
31
  export let display_icon_button_wrapper_top_corner = false;
32
  export let minimal = false;
33
+ export let playback_position = 0;
34
 
35
  const dispatch = createEventDispatcher<{
36
  change: FileData;
 
91
  {waveform_options}
92
  {editable}
93
  {loop}
94
+ bind:playback_position
95
  on:pause
96
  on:play
97
  on:stop