2024-02-06 05:05:38 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { createEventDispatcher, onMount } from 'svelte';
|
2024-02-11 10:12:49 +00:00
|
|
|
import toast from 'svelte-french-toast';
|
2024-02-06 05:05:38 +00:00
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
export let saveSettings: Function;
|
|
|
|
|
2024-02-11 10:21:06 +00:00
|
|
|
// Audio
|
2024-02-10 00:00:39 +00:00
|
|
|
|
2024-02-11 10:12:49 +00:00
|
|
|
let STTEngines = ['', 'openai'];
|
|
|
|
let STTEngine = '';
|
|
|
|
|
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-02-11 10:12:49 +00:00
|
|
|
let TTSEngines = ['', 'openai'];
|
|
|
|
let TTSEngine = '';
|
2024-02-06 05:36:03 +00:00
|
|
|
|
|
|
|
let voices = [];
|
|
|
|
let speaker = '';
|
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 01:09:14 +00:00
|
|
|
const toggleConversationMode = async () => {
|
|
|
|
conversationMode = !conversationMode;
|
2024-02-10 01:12:44 +00:00
|
|
|
|
|
|
|
if (conversationMode) {
|
|
|
|
responseAutoPlayback = true;
|
|
|
|
speechAutoSend = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
saveSettings({
|
|
|
|
conversationMode: conversationMode,
|
|
|
|
responseAutoPlayback: responseAutoPlayback,
|
|
|
|
speechAutoSend: speechAutoSend
|
|
|
|
});
|
2024-02-10 01:09:14 +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 () => {
|
|
|
|
let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
|
|
|
|
|
2024-02-10 01:09:14 +00:00
|
|
|
conversationMode = settings.conversationMode ?? false;
|
2024-02-10 00:37:21 +00:00
|
|
|
speechAutoSend = settings.speechAutoSend ?? false;
|
|
|
|
responseAutoPlayback = settings.responseAutoPlayback ?? false;
|
|
|
|
|
2024-02-11 10:21:06 +00:00
|
|
|
STTEngine = settings?.audio?.STTEngine ?? '';
|
|
|
|
TTSEngine = settings?.audio?.TTSEngine ?? '';
|
|
|
|
speaker = settings?.audio?.speaker ?? '';
|
2024-02-06 06:51:08 +00:00
|
|
|
|
2024-02-11 10:12:49 +00:00
|
|
|
if (TTSEngine === '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"
|
|
|
|
on:submit|preventDefault={() => {
|
|
|
|
saveSettings({
|
2024-02-11 10:21:06 +00:00
|
|
|
audio: {
|
2024-02-11 10:12:49 +00:00
|
|
|
STTEngine: STTEngine !== '' ? STTEngine : undefined,
|
|
|
|
TTSEngine: TTSEngine !== '' ? TTSEngine : undefined,
|
2024-02-06 06:51:08 +00:00
|
|
|
speaker: speaker !== '' ? speaker : undefined
|
|
|
|
}
|
2024-02-06 05:05:38 +00:00
|
|
|
});
|
|
|
|
dispatch('save');
|
|
|
|
}}
|
|
|
|
>
|
2024-02-11 10:12:49 +00:00
|
|
|
<div class=" space-y-3 pr-1.5 overflow-y-scroll max-h-80">
|
2024-02-10 00:00:39 +00:00
|
|
|
<div>
|
2024-02-11 10:12:49 +00:00
|
|
|
<div class=" mb-1 text-sm font-medium">STT Settings</div>
|
2024-02-10 00:00:39 +00:00
|
|
|
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
2024-02-11 10:12:49 +00:00
|
|
|
<div class=" self-center text-xs font-medium">Speech-to-Text Engine</div>
|
2024-02-10 00:00:39 +00:00
|
|
|
<div class="flex items-center relative">
|
|
|
|
<select
|
|
|
|
class="w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
|
2024-02-11 10:12:49 +00:00
|
|
|
bind:value={STTEngine}
|
2024-02-10 00:00:39 +00:00
|
|
|
placeholder="Select a mode"
|
|
|
|
on:change={(e) => {
|
2024-02-11 10:12:49 +00:00
|
|
|
if (e.target.value !== '') {
|
|
|
|
navigator.mediaDevices.getUserMedia({ audio: true }).catch(function (err) {
|
|
|
|
toast.error(`Permission denied when accessing microphone: ${err}`);
|
|
|
|
STTEngine = '';
|
|
|
|
});
|
2024-02-10 00:00:39 +00:00
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<option value="">Default (Web API)</option>
|
2024-02-11 10:12:49 +00:00
|
|
|
<option value="whisper-local">Whisper (Local)</option>
|
2024-02-10 00:00:39 +00:00
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
2024-02-10 01:09:14 +00:00
|
|
|
<div class=" self-center text-xs font-medium">Conversation Mode</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="p-1 px-3 text-xs flex rounded transition"
|
|
|
|
on:click={() => {
|
|
|
|
toggleConversationMode();
|
|
|
|
}}
|
|
|
|
type="button"
|
|
|
|
>
|
|
|
|
{#if conversationMode === true}
|
|
|
|
<span class="ml-2 self-center">On</span>
|
|
|
|
{:else}
|
|
|
|
<span class="ml-2 self-center">Off</span>
|
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
|
|
<div class=" self-center text-xs font-medium">Auto-send input after 3 sec.</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}
|
|
|
|
<span class="ml-2 self-center">On</span>
|
|
|
|
{:else}
|
|
|
|
<span class="ml-2 self-center">Off</span>
|
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
</div>
|
2024-02-11 10:12:49 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div>
|
|
|
|
<div class=" mb-1 text-sm font-medium">TTS Settings</div>
|
|
|
|
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
|
|
<div class=" self-center text-xs font-medium">Text-to-Speech Engine</div>
|
|
|
|
<div class="flex items-center relative">
|
|
|
|
<select
|
|
|
|
class="w-fit pr-8 rounded px-2 p-1 text-xs bg-transparent outline-none text-right"
|
|
|
|
bind:value={TTSEngine}
|
|
|
|
placeholder="Select a mode"
|
|
|
|
on:change={(e) => {
|
|
|
|
if (e.target.value === 'openai') {
|
|
|
|
getOpenAIVoices();
|
|
|
|
speaker = 'alloy';
|
|
|
|
} else {
|
|
|
|
getWebAPIVoices();
|
|
|
|
speaker = '';
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<option value="">Default (Web API)</option>
|
|
|
|
<option value="openai">Open AI</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-02-10 00:00:39 +00:00
|
|
|
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
2024-02-10 01:09:14 +00:00
|
|
|
<div class=" self-center text-xs font-medium">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}
|
|
|
|
<span class="ml-2 self-center">On</span>
|
|
|
|
{:else}
|
|
|
|
<span class="ml-2 self-center">Off</span>
|
|
|
|
{/if}
|
|
|
|
</button>
|
2024-02-06 05:36:03 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr class=" dark:border-gray-700" />
|
|
|
|
|
2024-02-11 10:12:49 +00:00
|
|
|
{#if TTSEngine === ''}
|
2024-02-06 05:05:38 +00:00
|
|
|
<div>
|
2024-02-06 05:36:03 +00:00
|
|
|
<div class=" mb-2.5 text-sm font-medium">Set Voice</div>
|
2024-02-06 05:05:38 +00:00
|
|
|
<div class="flex w-full">
|
|
|
|
<div class="flex-1">
|
|
|
|
<select
|
|
|
|
class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
|
2024-02-06 05:36:03 +00:00
|
|
|
bind:value={speaker}
|
2024-02-06 05:05:38 +00:00
|
|
|
placeholder="Select a voice"
|
|
|
|
>
|
|
|
|
<option value="" selected>Default</option>
|
2024-02-06 05:36:03 +00:00
|
|
|
{#each voices.filter((v) => v.localService === true) as voice}
|
2024-02-06 05:05:38 +00:00
|
|
|
<option value={voice.name} class="bg-gray-100 dark:bg-gray-700">{voice.name}</option
|
|
|
|
>
|
|
|
|
{/each}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-02-11 10:12:49 +00:00
|
|
|
{:else if TTSEngine === 'openai'}
|
2024-02-06 06:51:08 +00:00
|
|
|
<div>
|
|
|
|
<div class=" mb-2.5 text-sm font-medium">Set Voice</div>
|
|
|
|
<div class="flex w-full">
|
|
|
|
<div class="flex-1">
|
|
|
|
<select
|
|
|
|
class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
|
|
|
|
bind:value={speaker}
|
|
|
|
placeholder="Select a voice"
|
|
|
|
>
|
|
|
|
{#each voices as voice}
|
|
|
|
<option value={voice.name} class="bg-gray-100 dark:bg-gray-700">{voice.name}</option
|
|
|
|
>
|
|
|
|
{/each}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-02-06 05:36:03 +00:00
|
|
|
{/if}
|
2024-02-06 05:05:38 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex justify-end pt-3 text-sm font-medium">
|
|
|
|
<button
|
|
|
|
class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-gray-100 transition rounded"
|
|
|
|
type="submit"
|
|
|
|
>
|
|
|
|
Save
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</form>
|