2024-02-06 05:05:38 +00:00
|
|
|
<script lang="ts">
|
2024-06-08 03:18:48 +00:00
|
|
|
import { user, settings, config } from '$lib/stores';
|
2024-03-02 20:38:51 +00:00
|
|
|
import { createEventDispatcher, onMount, getContext } from 'svelte';
|
2024-03-01 09:18:07 +00:00
|
|
|
import { toast } from 'svelte-sonner';
|
2024-06-03 18:09:55 +00:00
|
|
|
import Switch from '$lib/components/common/Switch.svelte';
|
2024-02-06 05:05:38 +00:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
2024-03-02 20:38:51 +00:00
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
2024-02-06 05:05:38 +00:00
|
|
|
export let saveSettings: Function;
|
|
|
|
|
2024-02-11 10:21:06 +00:00
|
|
|
// Audio
|
2024-02-10 01:09:14 +00:00
|
|
|
let conversationMode = false;
|
2024-02-10 00:00:39 +00:00
|
|
|
let speechAutoSend = false;
|
|
|
|
let responseAutoPlayback = false;
|
2024-06-03 18:09:55 +00:00
|
|
|
let nonLocalVoices = false;
|
2024-02-10 00:00:39 +00:00
|
|
|
|
2024-06-08 03:18:48 +00:00
|
|
|
let STTEngine = '';
|
2024-02-06 05:36:03 +00:00
|
|
|
|
|
|
|
let voices = [];
|
2024-06-08 03:18:48 +00:00
|
|
|
let voice = '';
|
2024-02-06 05:05:38 +00:00
|
|
|
|
2024-02-06 06:51:08 +00:00
|
|
|
const getOpenAIVoices = () => {
|
|
|
|
voices = [
|
|
|
|
{ name: 'alloy' },
|
|
|
|
{ name: 'echo' },
|
|
|
|
{ name: 'fable' },
|
|
|
|
{ name: 'onyx' },
|
|
|
|
{ name: 'nova' },
|
|
|
|
{ name: 'shimmer' }
|
|
|
|
];
|
|
|
|
};
|
2024-02-06 05:05:38 +00:00
|
|
|
|
2024-02-06 06:51:08 +00:00
|
|
|
const getWebAPIVoices = () => {
|
2024-02-06 05:05:38 +00:00
|
|
|
const getVoicesLoop = setInterval(async () => {
|
2024-02-06 05:36:03 +00:00
|
|
|
voices = await speechSynthesis.getVoices();
|
2024-02-06 05:05:38 +00:00
|
|
|
|
|
|
|
// do your loop
|
2024-02-06 05:36:03 +00:00
|
|
|
if (voices.length > 0) {
|
2024-02-06 05:05:38 +00:00
|
|
|
clearInterval(getVoicesLoop);
|
|
|
|
}
|
|
|
|
}, 100);
|
2024-02-06 06:51:08 +00:00
|
|
|
};
|
|
|
|
|
2024-02-10 00:00:39 +00:00
|
|
|
const toggleResponseAutoPlayback = async () => {
|
|
|
|
responseAutoPlayback = !responseAutoPlayback;
|
|
|
|
saveSettings({ responseAutoPlayback: responseAutoPlayback });
|
|
|
|
};
|
|
|
|
|
|
|
|
const toggleSpeechAutoSend = async () => {
|
|
|
|
speechAutoSend = !speechAutoSend;
|
|
|
|
saveSettings({ speechAutoSend: speechAutoSend });
|
|
|
|
};
|
|
|
|
|
2024-02-06 06:51:08 +00:00
|
|
|
onMount(async () => {
|
2024-05-27 05:47:42 +00:00
|
|
|
conversationMode = $settings.conversationMode ?? false;
|
|
|
|
speechAutoSend = $settings.speechAutoSend ?? false;
|
|
|
|
responseAutoPlayback = $settings.responseAutoPlayback ?? false;
|
|
|
|
|
2024-06-08 03:18:48 +00:00
|
|
|
STTEngine = $settings?.audio?.stt?.engine ?? '';
|
|
|
|
voice = $settings?.audio?.tts?.voice ?? $config.audio.tts.voice ?? '';
|
|
|
|
nonLocalVoices = $settings.audio?.tts?.nonLocalVoices ?? false;
|
2024-02-06 06:51:08 +00:00
|
|
|
|
2024-06-08 03:18:48 +00:00
|
|
|
if ($config.audio.tts.engine === 'openai') {
|
2024-02-06 06:51:08 +00:00
|
|
|
getOpenAIVoices();
|
|
|
|
} else {
|
|
|
|
getWebAPIVoices();
|
|
|
|
}
|
2024-02-06 05:05:38 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<form
|
|
|
|
class="flex flex-col h-full justify-between space-y-3 text-sm"
|
2024-04-20 21:00:24 +00:00
|
|
|
on:submit|preventDefault={async () => {
|
2024-02-06 05:05:38 +00:00
|
|
|
saveSettings({
|
2024-02-11 10:21:06 +00:00
|
|
|
audio: {
|
2024-06-08 03:18:48 +00:00
|
|
|
stt: {
|
|
|
|
engine: STTEngine !== '' ? STTEngine : undefined
|
|
|
|
},
|
|
|
|
tts: {
|
2024-06-08 03:35:50 +00:00
|
|
|
voice: voice !== '' ? voice : undefined,
|
2024-06-08 03:18:48 +00:00
|
|
|
nonLocalVoices: $config.audio.tts.engine === '' ? nonLocalVoices : undefined
|
|
|
|
}
|
2024-02-06 06:51:08 +00:00
|
|
|
}
|
2024-02-06 05:05:38 +00:00
|
|
|
});
|
|
|
|
dispatch('save');
|
|
|
|
}}
|
|
|
|
>
|
2024-05-15 22:55:13 +00:00
|
|
|
<div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-[25rem]">
|
2024-02-10 00:00:39 +00:00
|
|
|
<div>
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" mb-1 text-sm font-medium">{$i18n.t('STT Settings')}</div>
|
2024-02-10 00:00:39 +00:00
|
|
|
|
2024-06-08 03:18:48 +00:00
|
|
|
{#if $config.audio.stt.engine !== 'web'}
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Speech-to-Text Engine')}</div>
|
|
|
|
<div class="flex items-center relative">
|
|
|
|
<select
|
|
|
|
class="dark:bg-gray-900 w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
|
|
|
|
bind:value={STTEngine}
|
|
|
|
placeholder="Select an engine"
|
|
|
|
>
|
|
|
|
<option value="">{$i18n.t('Default')}</option>
|
|
|
|
<option value="web">{$i18n.t('Web API')}</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
2024-02-10 00:00:39 +00:00
|
|
|
</div>
|
2024-06-08 03:18:48 +00:00
|
|
|
{/if}
|
2024-02-10 00:00:39 +00:00
|
|
|
|
2024-02-10 01:09:14 +00:00
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" self-center text-xs font-medium">
|
2024-06-07 04:56:09 +00:00
|
|
|
{$i18n.t('Instant Auto-Send After Voice Transcription')}
|
2024-03-02 20:38:51 +00:00
|
|
|
</div>
|
2024-02-10 00:00:39 +00:00
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={() => {
|
|
|
|
toggleSpeechAutoSend();
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
{#if speechAutoSend === true}
|
2024-03-02 20:38:51 +00:00
|
|
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
2024-02-10 00:00:39 +00:00
|
|
|
{:else}
|
2024-03-02 20:38:51 +00:00
|
|
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
2024-02-10 00:00:39 +00:00
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
2024-02-11 10:12:49 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" mb-1 text-sm font-medium">{$i18n.t('TTS Settings')}</div>
|
2024-02-11 10:12:49 +00:00
|
|
|
|
2024-02-10 00:00:39 +00:00
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Auto-playback response')}</div>
|
2024-02-10 00:00:39 +00:00
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={() => {
|
|
|
|
toggleResponseAutoPlayback();
|
2024-02-06 05:36:03 +00:00
|
|
|
}}
|
2024-02-10 00:00:39 +00:00
|
|
|
type="button"
|
2024-02-06 05:36:03 +00:00
|
|
|
>
|
2024-02-10 00:00:39 +00:00
|
|
|
{#if responseAutoPlayback === true}
|
2024-03-02 20:38:51 +00:00
|
|
|
<span class="ml-2 self-center">{$i18n.t('On')}</span>
|
2024-02-10 00:00:39 +00:00
|
|
|
{:else}
|
2024-03-02 20:38:51 +00:00
|
|
|
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
|
2024-02-10 00:00:39 +00:00
|
|
|
{/if}
|
|
|
|
</button>
|
2024-02-06 05:36:03 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr class=" dark:border-gray-700" />
|
|
|
|
|
2024-06-08 03:18:48 +00:00
|
|
|
{#if $config.audio.tts.engine === ''}
|
2024-02-06 05:05:38 +00:00
|
|
|
<div>
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" mb-2.5 text-sm font-medium">{$i18n.t('Set Voice')}</div>
|
2024-02-06 05:05:38 +00:00
|
|
|
<div class="flex w-full">
|
|
|
|
<div class="flex-1">
|
|
|
|
<select
|
2024-04-21 00:01:46 +00:00
|
|
|
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
|
2024-06-08 03:18:48 +00:00
|
|
|
bind:value={voice}
|
2024-02-06 05:05:38 +00:00
|
|
|
>
|
2024-06-08 03:18:48 +00:00
|
|
|
<option value="" selected={voice !== ''}>{$i18n.t('Default')}</option>
|
|
|
|
{#each voices.filter((v) => nonLocalVoices || v.localService === true) as _voice}
|
2024-06-03 18:09:55 +00:00
|
|
|
<option
|
2024-06-08 03:18:48 +00:00
|
|
|
value={_voice.name}
|
2024-06-03 18:09:55 +00:00
|
|
|
class="bg-gray-100 dark:bg-gray-700"
|
2024-06-08 03:18:48 +00:00
|
|
|
selected={voice === _voice.name}>{_voice.name}</option
|
2024-02-06 05:05:38 +00:00
|
|
|
>
|
|
|
|
{/each}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-05 15:48:02 +00:00
|
|
|
<div class="flex items-center justify-between my-1.5">
|
|
|
|
<div class="text-xs">
|
2024-06-03 18:09:55 +00:00
|
|
|
{$i18n.t('Allow non-local voices')}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="mt-1">
|
|
|
|
<Switch bind:state={nonLocalVoices} />
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-02-06 05:05:38 +00:00
|
|
|
</div>
|
2024-06-08 03:18:48 +00:00
|
|
|
{:else if $config.audio.tts.engine === 'openai'}
|
2024-02-06 06:51:08 +00:00
|
|
|
<div>
|
2024-03-02 20:38:51 +00:00
|
|
|
<div class=" mb-2.5 text-sm font-medium">{$i18n.t('Set Voice')}</div>
|
2024-02-06 06:51:08 +00:00
|
|
|
<div class="flex w-full">
|
|
|
|
<div class="flex-1">
|
2024-04-20 21:00:24 +00:00
|
|
|
<input
|
|
|
|
list="voice-list"
|
|
|
|
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
|
2024-06-08 03:18:48 +00:00
|
|
|
bind:value={voice}
|
2024-02-06 06:51:08 +00:00
|
|
|
placeholder="Select a voice"
|
2024-04-20 21:00:24 +00:00
|
|
|
/>
|
|
|
|
|
|
|
|
<datalist id="voice-list">
|
2024-02-06 06:51:08 +00:00
|
|
|
{#each voices as voice}
|
2024-04-20 21:00:24 +00:00
|
|
|
<option value={voice.name} />
|
2024-02-06 06:51:08 +00:00
|
|
|
{/each}
|
2024-04-20 21:00:24 +00:00
|
|
|
</datalist>
|
2024-02-06 06:51:08 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-02-06 05:36:03 +00:00
|
|
|
{/if}
|
2024-02-06 05:05:38 +00:00
|
|
|
</div>
|
|
|
|
|
2024-05-15 22:55:13 +00:00
|
|
|
<div class="flex justify-end text-sm font-medium">
|
2024-02-06 05:05:38 +00:00
|
|
|
<button
|
2024-03-10 06:02:27 +00:00
|
|
|
class=" px-4 py-2 bg-emerald-700 hover:bg-emerald-800 text-gray-100 transition rounded-lg"
|
2024-02-06 05:05:38 +00:00
|
|
|
type="submit"
|
|
|
|
>
|
2024-03-04 08:53:56 +00:00
|
|
|
{$i18n.t('Save')}
|
2024-02-06 05:05:38 +00:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|