-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Audio.svelte
105 lines (96 loc) 路 2.43 KB
/
Audio.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<script lang="ts">
import { createEventDispatcher } from "svelte";
import { _ } from "svelte-i18n";
import UploadText from "../UploadText.svelte";
import type { FileData } from "@gradio/upload";
import type { LoadingStatus } from "../StatusTracker/types";
import { Audio, StaticAudio } from "@gradio/audio";
import StatusTracker from "../StatusTracker/StatusTracker.svelte";
import { Block } from "@gradio/atoms";
import { normalise_file } from "@gradio/upload";
const dispatch = createEventDispatcher<{
change: typeof value;
stream: typeof value;
error: string;
}>();
export let elem_id: string = "";
export let elem_classes: Array<string> = [];
export let visible: boolean = true;
export let mode: "static" | "dynamic";
export let value: null | FileData | string = null;
export let name: string;
export let source: "microphone" | "upload";
export let label: string;
export let root: string;
export let show_label: boolean;
export let pending: boolean;
export let streaming: boolean;
export let root_url: null | string;
export let container: boolean = false;
export let scale: number = 1;
export let min_width: number | undefined = undefined;
export let loading_status: LoadingStatus;
export let autoplay: boolean = false;
let _value: null | FileData;
$: _value = normalise_file(value, root, root_url);
let dragging: boolean;
</script>
<Block
variant={mode === "dynamic" && value === null && source === "upload"
? "dashed"
: "solid"}
border_mode={dragging ? "focus" : "base"}
padding={false}
{elem_id}
{elem_classes}
{visible}
{container}
{scale}
{min_width}
>
<StatusTracker {...loading_status} />
{#if mode === "dynamic"}
<Audio
{label}
{show_label}
value={_value}
on:change={({ detail }) => {
value = detail;
dispatch("change", value);
}}
on:stream={({ detail }) => {
value = detail;
dispatch("stream", value);
}}
on:drag={({ detail }) => (dragging = detail)}
{name}
{source}
{pending}
{streaming}
{autoplay}
on:edit
on:play
on:pause
on:stop
on:end
on:start_recording
on:stop_recording
on:upload
on:error={({ detail }) => {
loading_status = loading_status || {};
loading_status.status = "error";
loading_status.message = detail;
}}
>
<UploadText type="audio" />
</Audio>
{:else}
<StaticAudio
{autoplay}
{show_label}
value={_value}
name={_value?.name || "audio_file"}
{label}
/>
{/if}
</Block>