refac
This commit is contained in:
1 parent
db934a3b4f
commit
ba067258de
39 files changed
+1540
-1442
No files matched your search
@@ -8,6 +8,9 @@
|
||||
import Switch from '$lib/components/common/Switch.svelte';
|
||||
import Spinner from '$lib/components/common/Spinner.svelte';
|
||||
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
||||
import UserSettingField from './UserSettingField.svelte';
|
||||
import UserSettingRow from './UserSettingRow.svelte';
|
||||
import UserSettingSection from './UserSettingSection.svelte';
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
const i18n = getContext('i18n');
|
||||
@@ -35,6 +38,12 @@
|
||||
|
||||
// Audio speed control
|
||||
let playbackRate = 1;
|
||||
const inputClass =
|
||||
'h-7 w-full rounded-lg border border-gray-100/50 bg-gray-50/40 px-2 text-xs text-gray-700 outline-hidden transition-colors placeholder:text-gray-300 focus:border-blue-400 dark:border-white/[0.04] dark:bg-white/[0.03] dark:text-gray-300 dark:placeholder:text-gray-700 dark:focus:border-blue-500';
|
||||
const selectClass =
|
||||
'h-7 w-fit min-w-28 rounded-lg border border-gray-100/50 bg-gray-50/40 px-2 text-right text-xs text-gray-700 outline-hidden transition-colors focus:border-blue-400 dark:border-white/[0.04] dark:bg-white/[0.03] dark:text-gray-300 dark:focus:border-blue-500';
|
||||
const actionButtonClass =
|
||||
'text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-gray-500 dark:hover:text-white';
|
||||
|
||||
const getVoices = async () => {
|
||||
if (TTSEngine === 'browser-kokoro') {
|
||||
@@ -154,7 +163,7 @@
|
||||
|
||||
<form
|
||||
id="tab-audio"
|
||||
class="flex flex-col h-full justify-between space-y-3 text-sm"
|
||||
class="flex flex-col h-full justify-between text-sm"
|
||||
on:submit|preventDefault={async () => {
|
||||
saveSettings({
|
||||
audio: {
|
||||
@@ -177,57 +186,55 @@
|
||||
>
|
||||
<h2 class="text-sm font-medium text-gray-900 dark:text-white mb-4">{$i18n.t('Audio')}</h2>
|
||||
|
||||
<div class="flex-1 min-h-0 overflow-y-auto scrollbar-hover pr-1.5 space-y-3">
|
||||
<div>
|
||||
<div class="text-xs text-gray-400 dark:text-gray-600 mb-2">
|
||||
{$i18n.t('STT Settings')}
|
||||
</div>
|
||||
|
||||
<div class="flex-1 min-h-0 overflow-y-auto scrollbar-hover pr-1.5">
|
||||
<UserSettingSection title={$i18n.t('STT Settings')} first>
|
||||
{#if $config.audio.stt.engine !== 'web'}
|
||||
<div class=" py-0.5 flex w-full justify-between">
|
||||
<div class=" self-center text-xs font-normal">{$i18n.t('Speech-to-Text Engine')}</div>
|
||||
<div class="flex items-center relative">
|
||||
<select
|
||||
class="w-fit pr-8 rounded-sm px-2 p-1 text-xs bg-transparent outline-hidden text-right"
|
||||
bind:value={STTEngine}
|
||||
aria-label={$i18n.t('Speech-to-Text Engine')}
|
||||
placeholder={$i18n.t('Select an engine')}
|
||||
>
|
||||
<option value="">{$i18n.t('Default')}</option>
|
||||
<option value="web">{$i18n.t('Web API')}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<UserSettingRow
|
||||
label={$i18n.t('Speech-to-Text Engine')}
|
||||
description={$i18n.t('Choose the engine used to transcribe voice input.')}
|
||||
>
|
||||
<select
|
||||
class={selectClass}
|
||||
bind:value={STTEngine}
|
||||
aria-label={$i18n.t('Speech-to-Text Engine')}
|
||||
placeholder={$i18n.t('Select an engine')}
|
||||
>
|
||||
<option value="">{$i18n.t('Default')}</option>
|
||||
<option value="web">{$i18n.t('Web API')}</option>
|
||||
</select>
|
||||
</UserSettingRow>
|
||||
|
||||
<div class=" py-0.5 flex w-full justify-between">
|
||||
<div class=" self-center text-xs font-normal">{$i18n.t('Language')}</div>
|
||||
|
||||
<div class="flex items-center relative text-xs px-3">
|
||||
<Tooltip
|
||||
content={$i18n.t(
|
||||
'The language of the input audio. Supplying the input language in ISO-639-1 (e.g. en) format will improve accuracy and latency. Leave blank to automatically detect the language.'
|
||||
)}
|
||||
placement="top"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
bind:value={STTLanguage}
|
||||
aria-label={$i18n.t('Speech-to-Text Language')}
|
||||
placeholder={$i18n.t('e.g. en')}
|
||||
class=" text-sm text-right bg-transparent dark:text-gray-300 outline-hidden"
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</div>
|
||||
<UserSettingRow
|
||||
label={$i18n.t('Language')}
|
||||
description={$i18n.t(
|
||||
'Set a speech recognition language or leave it blank to detect automatically.'
|
||||
)}
|
||||
>
|
||||
<Tooltip
|
||||
content={$i18n.t(
|
||||
'The language of the input audio. Supplying the input language in ISO-639-1 (e.g. en) format will improve accuracy and latency. Leave blank to automatically detect the language.'
|
||||
)}
|
||||
placement="top"
|
||||
>
|
||||
<input
|
||||
type="text"
|
||||
bind:value={STTLanguage}
|
||||
aria-label={$i18n.t('Speech-to-Text Language')}
|
||||
placeholder={$i18n.t('e.g. en')}
|
||||
class="h-7 w-24 rounded-lg border border-gray-100/50 bg-gray-50/40 px-2 text-right text-xs text-gray-700 outline-hidden transition-colors placeholder:text-gray-300 focus:border-blue-400 dark:border-white/[0.04] dark:bg-white/[0.03] dark:text-gray-300 dark:placeholder:text-gray-700 dark:focus:border-blue-500"
|
||||
/>
|
||||
</Tooltip>
|
||||
</UserSettingRow>
|
||||
{/if}
|
||||
|
||||
<div class=" py-0.5 flex w-full justify-between">
|
||||
<div class=" self-center text-xs font-normal">
|
||||
{$i18n.t('Instant Auto-Send After Voice Transcription')}
|
||||
</div>
|
||||
|
||||
<UserSettingRow
|
||||
label={$i18n.t('Instant Auto-Send After Voice Transcription')}
|
||||
description={$i18n.t(
|
||||
'Send transcribed voice input immediately after speech recognition finishes.'
|
||||
)}
|
||||
>
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded-sm transition"
|
||||
class={actionButtonClass}
|
||||
on:click={() => {
|
||||
toggleSpeechAutoSend();
|
||||
}}
|
||||
@@ -235,60 +242,53 @@
|
||||
role="switch"
|
||||
aria-checked={speechAutoSend}
|
||||
>
|
||||
{#if speechAutoSend === true}
|
||||
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
||||
{:else}
|
||||
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
||||
{/if}
|
||||
{speechAutoSend === true ? $i18n.t('On') : $i18n.t('Off')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</UserSettingRow>
|
||||
</UserSettingSection>
|
||||
|
||||
<div>
|
||||
<div class="text-xs text-gray-400 dark:text-gray-600 mb-2">
|
||||
{$i18n.t('TTS Settings')}
|
||||
</div>
|
||||
|
||||
<div class=" py-0.5 flex w-full justify-between">
|
||||
<div class=" self-center text-xs font-normal">{$i18n.t('Text-to-Speech Engine')}</div>
|
||||
<div class="flex items-center relative">
|
||||
<select
|
||||
class="w-fit pr-8 rounded-sm px-2 p-1 text-xs bg-transparent outline-hidden text-right"
|
||||
bind:value={TTSEngine}
|
||||
aria-label={$i18n.t('Text-to-Speech Engine')}
|
||||
placeholder={$i18n.t('Select an engine')}
|
||||
>
|
||||
<option value="">{$i18n.t('Default')}</option>
|
||||
<option value="browser-kokoro">{$i18n.t('Kokoro.js (Browser)')}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<UserSettingSection title={$i18n.t('TTS Settings')}>
|
||||
<UserSettingRow
|
||||
label={$i18n.t('Text-to-Speech Engine')}
|
||||
description={$i18n.t('Choose the engine used to read assistant responses aloud.')}
|
||||
>
|
||||
<select
|
||||
class={selectClass}
|
||||
bind:value={TTSEngine}
|
||||
aria-label={$i18n.t('Text-to-Speech Engine')}
|
||||
placeholder={$i18n.t('Select an engine')}
|
||||
>
|
||||
<option value="">{$i18n.t('Default')}</option>
|
||||
<option value="browser-kokoro">{$i18n.t('Kokoro.js (Browser)')}</option>
|
||||
</select>
|
||||
</UserSettingRow>
|
||||
|
||||
{#if TTSEngine === 'browser-kokoro'}
|
||||
<div class=" py-0.5 flex w-full justify-between">
|
||||
<div class=" self-center text-xs font-normal">{$i18n.t('Kokoro.js Dtype')}</div>
|
||||
<div class="flex items-center relative">
|
||||
<select
|
||||
class="w-fit pr-8 rounded-sm px-2 p-1 text-xs bg-transparent outline-hidden text-right"
|
||||
bind:value={TTSEngineConfig.dtype}
|
||||
aria-label={$i18n.t('Kokoro.js Dtype')}
|
||||
placeholder={$i18n.t('Select dtype')}
|
||||
>
|
||||
<option value="" disabled selected>{$i18n.t('Select dtype')}</option>
|
||||
<option value="fp32">fp32</option>
|
||||
<option value="fp16">fp16</option>
|
||||
<option value="q8">q8</option>
|
||||
<option value="q4">q4</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<UserSettingRow
|
||||
label={$i18n.t('Kokoro.js Dtype')}
|
||||
description={$i18n.t('Select the local model precision used by Kokoro.js.')}
|
||||
>
|
||||
<select
|
||||
class={selectClass}
|
||||
bind:value={TTSEngineConfig.dtype}
|
||||
aria-label={$i18n.t('Kokoro.js Dtype')}
|
||||
placeholder={$i18n.t('Select dtype')}
|
||||
>
|
||||
<option value="" disabled selected>{$i18n.t('Select dtype')}</option>
|
||||
<option value="fp32">fp32</option>
|
||||
<option value="fp16">fp16</option>
|
||||
<option value="q8">q8</option>
|
||||
<option value="q4">q4</option>
|
||||
</select>
|
||||
</UserSettingRow>
|
||||
{/if}
|
||||
|
||||
<div class=" py-0.5 flex w-full justify-between">
|
||||
<div class=" self-center text-xs font-normal">{$i18n.t('Auto-Playback Response')}</div>
|
||||
|
||||
<UserSettingRow
|
||||
label={$i18n.t('Auto-Playback Response')}
|
||||
description={$i18n.t('Play assistant responses aloud automatically.')}
|
||||
>
|
||||
<button
|
||||
class="p-1 px-3 text-xs flex rounded-sm transition"
|
||||
class={actionButtonClass}
|
||||
on:click={() => {
|
||||
toggleResponseAutoPlayback();
|
||||
}}
|
||||
@@ -296,114 +296,38 @@
|
||||
role="switch"
|
||||
aria-checked={responseAutoPlayback}
|
||||
>
|
||||
{#if responseAutoPlayback === true}
|
||||
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
||||
{:else}
|
||||
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
||||
{/if}
|
||||
{responseAutoPlayback === true ? $i18n.t('On') : $i18n.t('Off')}
|
||||
</button>
|
||||
</div>
|
||||
</UserSettingRow>
|
||||
|
||||
<div class=" py-0.5 flex w-full justify-between">
|
||||
<div class=" self-center text-xs font-normal">{$i18n.t('Speech Playback Speed')}</div>
|
||||
|
||||
<div class="flex items-center relative text-xs px-3">
|
||||
<UserSettingRow
|
||||
label={$i18n.t('Speech Playback Speed')}
|
||||
description={$i18n.t('Adjust how quickly spoken responses are played.')}
|
||||
>
|
||||
<div class="relative flex items-center gap-1.5 text-xs text-gray-400 dark:text-gray-600">
|
||||
<input
|
||||
type="number"
|
||||
min="0"
|
||||
step="0.01"
|
||||
bind:value={playbackRate}
|
||||
aria-label={$i18n.t('Speech Playback Speed')}
|
||||
class=" text-sm text-right bg-transparent dark:text-gray-300 outline-hidden"
|
||||
class="h-7 w-16 rounded-lg border border-gray-100/50 bg-gray-50/40 px-2 text-right text-xs text-gray-700 outline-hidden transition-colors focus:border-blue-400 dark:border-white/[0.04] dark:bg-white/[0.03] dark:text-gray-300 dark:focus:border-blue-500"
|
||||
/>
|
||||
x
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class=" border-gray-100/20 dark:border-white/[0.025]" />
|
||||
</UserSettingRow>
|
||||
</UserSettingSection>
|
||||
|
||||
{#if TTSEngine === 'browser-kokoro'}
|
||||
{#if TTSModel}
|
||||
<div>
|
||||
<div class="text-xs text-gray-400 dark:text-gray-600 mb-2.5">
|
||||
{$i18n.t('Set Voice')}
|
||||
</div>
|
||||
<div class="flex w-full">
|
||||
<div class="flex-1">
|
||||
<input
|
||||
list="voice-list"
|
||||
class="w-full text-sm bg-transparent dark:text-gray-300 outline-hidden"
|
||||
bind:value={voice}
|
||||
aria-label={$i18n.t('Voice')}
|
||||
placeholder={$i18n.t('Select a voice')}
|
||||
/>
|
||||
|
||||
<datalist id="voice-list">
|
||||
{#each voices as voice}
|
||||
<option value={voice.id}>{voice.name}</option>
|
||||
{/each}
|
||||
</datalist>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div>
|
||||
<div class=" mb-2.5 text-sm font-normal flex gap-2 items-center">
|
||||
<Spinner className="size-4" />
|
||||
|
||||
<div class=" text-sm font-normal shimmer">
|
||||
{$i18n.t('Loading Kokoro.js...')}
|
||||
{TTSModelProgress && TTSModelProgress.status === 'progress'
|
||||
? `(${Math.round(TTSModelProgress.progress * 10) / 10}%)`
|
||||
: ''}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('Please do not close the settings page while loading the model.')}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{:else if $config.audio.tts.engine === ''}
|
||||
<div>
|
||||
<div class=" mb-2.5 text-sm font-normal">{$i18n.t('Set Voice')}</div>
|
||||
<div class="flex w-full">
|
||||
<div class="flex-1">
|
||||
<select
|
||||
class="w-full text-sm bg-transparent dark:text-gray-300 outline-hidden"
|
||||
bind:value={voice}
|
||||
aria-label={$i18n.t('Voice')}
|
||||
>
|
||||
<option value="" selected={voice !== ''}>{$i18n.t('Default')}</option>
|
||||
{#each voices.filter((v) => nonLocalVoices || v.localService === true) as _voice}
|
||||
<option
|
||||
value={_voice.name}
|
||||
class="bg-gray-100 dark:bg-gray-700"
|
||||
selected={voice === _voice.name}>{_voice.name}</option
|
||||
>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center justify-between my-1.5">
|
||||
<div class="text-xs">
|
||||
{$i18n.t('Allow non-local voices')}
|
||||
</div>
|
||||
|
||||
<div class="mt-1">
|
||||
<Switch bind:state={nonLocalVoices} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{:else if $config.audio.tts.engine !== ''}
|
||||
<div>
|
||||
<div class=" mb-2.5 text-sm font-normal">{$i18n.t('Set Voice')}</div>
|
||||
<div class="flex w-full">
|
||||
<div class="flex-1">
|
||||
<UserSettingSection title={$i18n.t('Voice')}>
|
||||
<UserSettingField
|
||||
label={$i18n.t('Set Voice')}
|
||||
description={$i18n.t('Choose the Kokoro.js voice used for speech output.')}
|
||||
>
|
||||
<input
|
||||
list="voice-list"
|
||||
class="w-full text-sm bg-transparent dark:text-gray-300 outline-hidden"
|
||||
class={inputClass}
|
||||
bind:value={voice}
|
||||
aria-label={$i18n.t('Voice')}
|
||||
placeholder={$i18n.t('Select a voice')}
|
||||
@@ -414,9 +338,71 @@
|
||||
<option value={voice.id}>{voice.name}</option>
|
||||
{/each}
|
||||
</datalist>
|
||||
</UserSettingField>
|
||||
</UserSettingSection>
|
||||
{:else}
|
||||
<UserSettingSection title={$i18n.t('Voice')}>
|
||||
<div class="flex items-center gap-2 text-xs text-gray-600 dark:text-gray-400">
|
||||
<Spinner className="size-4" />
|
||||
|
||||
<div class="shimmer">
|
||||
{$i18n.t('Loading Kokoro.js...')}
|
||||
{TTSModelProgress && TTSModelProgress.status === 'progress'
|
||||
? `(${Math.round(TTSModelProgress.progress * 10) / 10}%)`
|
||||
: ''}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="text-[0.6875rem] text-gray-400 dark:text-gray-600">
|
||||
{$i18n.t('Please do not close the settings page while loading the model.')}
|
||||
</div>
|
||||
</UserSettingSection>
|
||||
{/if}
|
||||
{:else if $config.audio.tts.engine === ''}
|
||||
<UserSettingSection title={$i18n.t('Voice')}>
|
||||
<UserSettingField
|
||||
label={$i18n.t('Set Voice')}
|
||||
description={$i18n.t('Choose the browser voice used for speech output.')}
|
||||
>
|
||||
<select class={inputClass} bind:value={voice} aria-label={$i18n.t('Voice')}>
|
||||
<option value="" selected={voice !== ''}>{$i18n.t('Default')}</option>
|
||||
{#each voices.filter((v) => nonLocalVoices || v.localService === true) as _voice}
|
||||
<option
|
||||
value={_voice.name}
|
||||
class="bg-gray-100 dark:bg-gray-700"
|
||||
selected={voice === _voice.name}>{_voice.name}</option
|
||||
>
|
||||
{/each}
|
||||
</select>
|
||||
</UserSettingField>
|
||||
<UserSettingRow
|
||||
label={$i18n.t('Allow non-local voices')}
|
||||
description={$i18n.t('Include voices that are not provided by a local speech service.')}
|
||||
>
|
||||
<Switch bind:state={nonLocalVoices} />
|
||||
</UserSettingRow>
|
||||
</UserSettingSection>
|
||||
{:else if $config.audio.tts.engine !== ''}
|
||||
<UserSettingSection title={$i18n.t('Voice')}>
|
||||
<UserSettingField
|
||||
label={$i18n.t('Set Voice')}
|
||||
description={$i18n.t('Choose the configured text-to-speech service voice.')}
|
||||
>
|
||||
<input
|
||||
list="voice-list"
|
||||
class={inputClass}
|
||||
bind:value={voice}
|
||||
aria-label={$i18n.t('Voice')}
|
||||
placeholder={$i18n.t('Select a voice')}
|
||||
/>
|
||||
|
||||
<datalist id="voice-list">
|
||||
{#each voices as voice}
|
||||
<option value={voice.id}>{voice.name}</option>
|
||||
{/each}
|
||||
</datalist>
|
||||
</UserSettingField>
|
||||
</UserSettingSection>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user