adf0d17497
publish / version_or_publish (push) Has been cancelled
storybook-build / changes (push) Has been cancelled
storybook-build / :storybook-build (push) Has been cancelled
Sync Gradio Skills to Hugging Face / sync-skills (push) Has been cancelled
functional / changes (push) Has been cancelled
functional / build-frontend (push) Has been cancelled
functional / functional-test-SSR=false (push) Has been cancelled
functional / functional-reload (push) Has been cancelled
js / changes (push) Has been cancelled
js / js-test (push) Has been cancelled
docs-build / changes (push) Has been cancelled
docs-build / docs-build (push) Has been cancelled
docs-build / website-build (push) Has been cancelled
functional / functional-test-SSR=true (push) Has been cancelled
hygiene / hygiene-test (push) Has been cancelled
python / changes (push) Has been cancelled
python / build (push) Has been cancelled
python / test-ubuntu-latest-flaky (push) Has been cancelled
python / test-ubuntu-latest-not-flaky (push) Has been cancelled
python / test-windows-latest-flaky (push) Has been cancelled
python / test-windows-latest-not-flaky (push) Has been cancelled
215 lines
4.6 KiB
Svelte
215 lines
4.6 KiB
Svelte
<script lang="ts">
|
|
import { onMount } from "svelte";
|
|
import type { I18nFormatter } from "@gradio/utils";
|
|
import { Spinner } from "@gradio/icons";
|
|
import WaveSurfer from "wavesurfer.js";
|
|
import RecordPlugin from "wavesurfer.js/dist/plugins/record.js";
|
|
import type { WaveformOptions } from "../shared/types";
|
|
import DeviceSelect from "../shared/DeviceSelect.svelte";
|
|
|
|
let {
|
|
recording = false,
|
|
paused_recording = false,
|
|
stop,
|
|
record,
|
|
i18n,
|
|
waveform_settings,
|
|
waveform_options = { show_recording_waveform: true },
|
|
waiting = false
|
|
}: {
|
|
recording?: boolean;
|
|
paused_recording?: boolean;
|
|
stop: () => void;
|
|
record: () => void;
|
|
i18n: I18nFormatter;
|
|
waveform_settings: Record<string, any>;
|
|
waveform_options?: WaveformOptions;
|
|
waiting?: boolean;
|
|
} = $props();
|
|
|
|
let micWaveform: WaveSurfer;
|
|
let waveformRecord: RecordPlugin;
|
|
|
|
let microphoneContainer: HTMLDivElement;
|
|
|
|
let micDevices: MediaDeviceInfo[] = $state([]);
|
|
|
|
onMount(() => {
|
|
create_mic_waveform();
|
|
});
|
|
|
|
const create_mic_waveform = (): void => {
|
|
if (micWaveform !== undefined) micWaveform.destroy();
|
|
if (!microphoneContainer) return;
|
|
micWaveform = WaveSurfer.create({
|
|
...waveform_settings,
|
|
normalize: false,
|
|
container: microphoneContainer
|
|
});
|
|
|
|
waveformRecord = micWaveform.registerPlugin(RecordPlugin.create());
|
|
};
|
|
</script>
|
|
|
|
<div class="mic-wrap">
|
|
{#if waveform_options.show_recording_waveform}
|
|
<div
|
|
bind:this={microphoneContainer}
|
|
style:display={recording ? "block" : "none"}
|
|
/>
|
|
{/if}
|
|
<div class="controls">
|
|
{#if recording && !waiting}
|
|
<button
|
|
class={paused_recording ? "stop-button-paused" : "stop-button"}
|
|
onclick={() => {
|
|
waveformRecord?.stopMic();
|
|
stop();
|
|
}}
|
|
>
|
|
<span class="record-icon">
|
|
<span class="pinger" />
|
|
<span class="dot" />
|
|
</span>
|
|
{paused_recording ? i18n("audio.pause") : i18n("audio.stop")}
|
|
</button>
|
|
{:else if recording && waiting}
|
|
<button
|
|
class="spinner-button"
|
|
onclick={() => {
|
|
stop();
|
|
}}
|
|
>
|
|
<div class="icon">
|
|
<Spinner />
|
|
</div>
|
|
{i18n("audio.waiting")}
|
|
</button>
|
|
{:else}
|
|
<button
|
|
class="record-button"
|
|
onclick={() => {
|
|
waveformRecord?.startMic();
|
|
record();
|
|
}}
|
|
>
|
|
<span class="record-icon">
|
|
<span class="dot" />
|
|
</span>
|
|
{i18n("audio.record")}
|
|
</button>
|
|
{/if}
|
|
|
|
<DeviceSelect bind:micDevices {i18n} />
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.controls {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.mic-wrap {
|
|
display: block;
|
|
align-items: center;
|
|
margin: var(--spacing-xl);
|
|
}
|
|
|
|
.icon {
|
|
width: var(--size-4);
|
|
height: var(--size-4);
|
|
fill: var(--primary-600);
|
|
stroke: var(--primary-600);
|
|
}
|
|
|
|
.stop-button-paused {
|
|
display: none;
|
|
height: var(--size-8);
|
|
width: var(--size-20);
|
|
background-color: var(--block-background-fill);
|
|
border-radius: var(--button-large-radius);
|
|
align-items: center;
|
|
border: 1px solid var(--block-border-color);
|
|
margin-right: 5px;
|
|
}
|
|
|
|
.stop-button-paused::before {
|
|
content: "";
|
|
height: var(--size-4);
|
|
width: var(--size-4);
|
|
border-radius: var(--radius-full);
|
|
background: var(--primary-600);
|
|
margin: 0 var(--spacing-xl);
|
|
}
|
|
|
|
.stop-button::before {
|
|
content: "";
|
|
height: var(--size-4);
|
|
width: var(--size-4);
|
|
border-radius: var(--radius-full);
|
|
background: var(--primary-600);
|
|
margin: 0 var(--spacing-xl);
|
|
animation: scaling 1800ms infinite;
|
|
}
|
|
|
|
.stop-button {
|
|
height: var(--size-8);
|
|
width: var(--size-20);
|
|
background-color: var(--block-background-fill);
|
|
border-radius: var(--button-large-radius);
|
|
align-items: center;
|
|
border: 1px solid var(--primary-600);
|
|
margin-right: 5px;
|
|
display: flex;
|
|
}
|
|
|
|
.spinner-button {
|
|
height: var(--size-8);
|
|
width: var(--size-24);
|
|
background-color: var(--block-background-fill);
|
|
border-radius: var(--radius-3xl);
|
|
align-items: center;
|
|
border: 1px solid var(--primary-600);
|
|
margin: 0 var(--spacing-xl);
|
|
display: flex;
|
|
justify-content: space-evenly;
|
|
}
|
|
|
|
.record-button::before {
|
|
content: "";
|
|
height: var(--size-4);
|
|
width: var(--size-4);
|
|
border-radius: var(--radius-full);
|
|
background: var(--primary-600);
|
|
margin: 0 var(--spacing-xl);
|
|
}
|
|
|
|
.record-button {
|
|
height: var(--size-8);
|
|
width: var(--size-24);
|
|
background-color: var(--block-background-fill);
|
|
border-radius: var(--button-large-radius);
|
|
display: flex;
|
|
align-items: center;
|
|
border: 1px solid var(--block-border-color);
|
|
}
|
|
|
|
@keyframes scaling {
|
|
0% {
|
|
background-color: var(--primary-600);
|
|
scale: 1;
|
|
}
|
|
50% {
|
|
background-color: var(--primary-600);
|
|
scale: 1.2;
|
|
}
|
|
100% {
|
|
background-color: var(--primary-600);
|
|
scale: 1;
|
|
}
|
|
}
|
|
</style>
|