|
@@ -1,6 +1,5 @@
|
|
<script lang="ts">
|
|
<script lang="ts">
|
|
- import { getAudioConfig, updateAudioConfig } from '$lib/apis/audio';
|
|
|
|
- import { user, settings } from '$lib/stores';
|
|
|
|
|
|
+ import { user, settings, config } from '$lib/stores';
|
|
import { createEventDispatcher, onMount, getContext } from 'svelte';
|
|
import { createEventDispatcher, onMount, getContext } from 'svelte';
|
|
import { toast } from 'svelte-sonner';
|
|
import { toast } from 'svelte-sonner';
|
|
import Switch from '$lib/components/common/Switch.svelte';
|
|
import Switch from '$lib/components/common/Switch.svelte';
|
|
@@ -11,26 +10,15 @@
|
|
export let saveSettings: Function;
|
|
export let saveSettings: Function;
|
|
|
|
|
|
// Audio
|
|
// Audio
|
|
-
|
|
|
|
- let OpenAIUrl = '';
|
|
|
|
- let OpenAIKey = '';
|
|
|
|
- let OpenAISpeaker = '';
|
|
|
|
-
|
|
|
|
- let STTEngines = ['', 'openai'];
|
|
|
|
- let STTEngine = '';
|
|
|
|
-
|
|
|
|
let conversationMode = false;
|
|
let conversationMode = false;
|
|
let speechAutoSend = false;
|
|
let speechAutoSend = false;
|
|
let responseAutoPlayback = false;
|
|
let responseAutoPlayback = false;
|
|
let nonLocalVoices = false;
|
|
let nonLocalVoices = false;
|
|
|
|
|
|
- let TTSEngines = ['', 'openai'];
|
|
|
|
- let TTSEngine = '';
|
|
|
|
|
|
+ let STTEngine = '';
|
|
|
|
|
|
let voices = [];
|
|
let voices = [];
|
|
- let speaker = '';
|
|
|
|
- let models = [];
|
|
|
|
- let model = '';
|
|
|
|
|
|
+ let voice = '';
|
|
|
|
|
|
const getOpenAIVoices = () => {
|
|
const getOpenAIVoices = () => {
|
|
voices = [
|
|
voices = [
|
|
@@ -43,10 +31,6 @@
|
|
];
|
|
];
|
|
};
|
|
};
|
|
|
|
|
|
- const getOpenAIVoicesModel = () => {
|
|
|
|
- models = [{ name: 'tts-1' }, { name: 'tts-1-hd' }];
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
const getWebAPIVoices = () => {
|
|
const getWebAPIVoices = () => {
|
|
const getVoicesLoop = setInterval(async () => {
|
|
const getVoicesLoop = setInterval(async () => {
|
|
voices = await speechSynthesis.getVoices();
|
|
voices = await speechSynthesis.getVoices();
|
|
@@ -58,21 +42,6 @@
|
|
}, 100);
|
|
}, 100);
|
|
};
|
|
};
|
|
|
|
|
|
- const toggleConversationMode = async () => {
|
|
|
|
- conversationMode = !conversationMode;
|
|
|
|
-
|
|
|
|
- if (conversationMode) {
|
|
|
|
- responseAutoPlayback = true;
|
|
|
|
- speechAutoSend = true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- saveSettings({
|
|
|
|
- conversationMode: conversationMode,
|
|
|
|
- responseAutoPlayback: responseAutoPlayback,
|
|
|
|
- speechAutoSend: speechAutoSend
|
|
|
|
- });
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
const toggleResponseAutoPlayback = async () => {
|
|
const toggleResponseAutoPlayback = async () => {
|
|
responseAutoPlayback = !responseAutoPlayback;
|
|
responseAutoPlayback = !responseAutoPlayback;
|
|
saveSettings({ responseAutoPlayback: responseAutoPlayback });
|
|
saveSettings({ responseAutoPlayback: responseAutoPlayback });
|
|
@@ -83,76 +52,35 @@
|
|
saveSettings({ speechAutoSend: speechAutoSend });
|
|
saveSettings({ speechAutoSend: speechAutoSend });
|
|
};
|
|
};
|
|
|
|
|
|
- const updateConfigHandler = async () => {
|
|
|
|
- if (TTSEngine === 'openai') {
|
|
|
|
- const res = await updateAudioConfig(localStorage.token, {
|
|
|
|
- url: OpenAIUrl,
|
|
|
|
- key: OpenAIKey,
|
|
|
|
- model: model,
|
|
|
|
- speaker: OpenAISpeaker
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- if (res) {
|
|
|
|
- OpenAIUrl = res.OPENAI_API_BASE_URL;
|
|
|
|
- OpenAIKey = res.OPENAI_API_KEY;
|
|
|
|
- model = res.OPENAI_API_MODEL;
|
|
|
|
- OpenAISpeaker = res.OPENAI_API_VOICE;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
onMount(async () => {
|
|
onMount(async () => {
|
|
conversationMode = $settings.conversationMode ?? false;
|
|
conversationMode = $settings.conversationMode ?? false;
|
|
speechAutoSend = $settings.speechAutoSend ?? false;
|
|
speechAutoSend = $settings.speechAutoSend ?? false;
|
|
responseAutoPlayback = $settings.responseAutoPlayback ?? false;
|
|
responseAutoPlayback = $settings.responseAutoPlayback ?? false;
|
|
|
|
|
|
- STTEngine = $settings?.audio?.STTEngine ?? '';
|
|
|
|
- TTSEngine = $settings?.audio?.TTSEngine ?? '';
|
|
|
|
- nonLocalVoices = $settings.audio?.nonLocalVoices ?? false;
|
|
|
|
- speaker = $settings?.audio?.speaker ?? '';
|
|
|
|
- model = $settings?.audio?.model ?? '';
|
|
|
|
|
|
+ STTEngine = $settings?.audio?.stt?.engine ?? '';
|
|
|
|
+ voice = $settings?.audio?.tts?.voice ?? $config.audio.tts.voice ?? '';
|
|
|
|
+ nonLocalVoices = $settings.audio?.tts?.nonLocalVoices ?? false;
|
|
|
|
|
|
- if (TTSEngine === 'openai') {
|
|
|
|
|
|
+ if ($config.audio.tts.engine === 'openai') {
|
|
getOpenAIVoices();
|
|
getOpenAIVoices();
|
|
- getOpenAIVoicesModel();
|
|
|
|
} else {
|
|
} else {
|
|
getWebAPIVoices();
|
|
getWebAPIVoices();
|
|
}
|
|
}
|
|
-
|
|
|
|
- if ($user.role === 'admin') {
|
|
|
|
- const res = await getAudioConfig(localStorage.token);
|
|
|
|
-
|
|
|
|
- if (res) {
|
|
|
|
- OpenAIUrl = res.OPENAI_API_BASE_URL;
|
|
|
|
- OpenAIKey = res.OPENAI_API_KEY;
|
|
|
|
- model = res.OPENAI_API_MODEL;
|
|
|
|
- OpenAISpeaker = res.OPENAI_API_VOICE;
|
|
|
|
- if (TTSEngine === 'openai') {
|
|
|
|
- speaker = OpenAISpeaker;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
});
|
|
});
|
|
</script>
|
|
</script>
|
|
|
|
|
|
<form
|
|
<form
|
|
class="flex flex-col h-full justify-between space-y-3 text-sm"
|
|
class="flex flex-col h-full justify-between space-y-3 text-sm"
|
|
on:submit|preventDefault={async () => {
|
|
on:submit|preventDefault={async () => {
|
|
- if ($user.role === 'admin') {
|
|
|
|
- await updateConfigHandler();
|
|
|
|
- }
|
|
|
|
saveSettings({
|
|
saveSettings({
|
|
audio: {
|
|
audio: {
|
|
- STTEngine: STTEngine !== '' ? STTEngine : undefined,
|
|
|
|
- TTSEngine: TTSEngine !== '' ? TTSEngine : undefined,
|
|
|
|
- speaker:
|
|
|
|
- (TTSEngine === 'openai' ? OpenAISpeaker : speaker) !== ''
|
|
|
|
- ? TTSEngine === 'openai'
|
|
|
|
- ? OpenAISpeaker
|
|
|
|
- : speaker
|
|
|
|
- : undefined,
|
|
|
|
- model: model !== '' ? model : undefined,
|
|
|
|
- nonLocalVoices: nonLocalVoices
|
|
|
|
|
|
+ stt: {
|
|
|
|
+ engine: STTEngine !== '' ? STTEngine : undefined
|
|
|
|
+ },
|
|
|
|
+ tts: {
|
|
|
|
+ voice: $config.audio.tts.engine === 'openai' ? voice : voice !== '' ? voice : undefined,
|
|
|
|
+ nonLocalVoices: $config.audio.tts.engine === '' ? nonLocalVoices : undefined
|
|
|
|
+ }
|
|
}
|
|
}
|
|
});
|
|
});
|
|
dispatch('save');
|
|
dispatch('save');
|
|
@@ -162,31 +90,21 @@
|
|
<div>
|
|
<div>
|
|
<div class=" mb-1 text-sm font-medium">{$i18n.t('STT Settings')}</div>
|
|
<div class=" mb-1 text-sm font-medium">{$i18n.t('STT Settings')}</div>
|
|
|
|
|
|
- <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"
|
|
|
|
- on:change={(e) => {
|
|
|
|
- if (e.target.value !== '') {
|
|
|
|
- navigator.mediaDevices.getUserMedia({ audio: true }).catch(function (err) {
|
|
|
|
- toast.error(
|
|
|
|
- $i18n.t(`Permission denied when accessing microphone: {{error}}`, {
|
|
|
|
- error: err
|
|
|
|
- })
|
|
|
|
- );
|
|
|
|
- STTEngine = '';
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
- }}
|
|
|
|
- >
|
|
|
|
- <option value="">{$i18n.t('Default (Whisper)')}</option>
|
|
|
|
- <option value="web">{$i18n.t('Web API')}</option>
|
|
|
|
- </select>
|
|
|
|
|
|
+ {#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>
|
|
</div>
|
|
</div>
|
|
- </div>
|
|
|
|
|
|
+ {/if}
|
|
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
<div class=" self-center text-xs font-medium">
|
|
<div class=" self-center text-xs font-medium">
|
|
@@ -212,50 +130,6 @@
|
|
<div>
|
|
<div>
|
|
<div class=" mb-1 text-sm font-medium">{$i18n.t('TTS Settings')}</div>
|
|
<div class=" mb-1 text-sm font-medium">{$i18n.t('TTS Settings')}</div>
|
|
|
|
|
|
- <div class=" py-0.5 flex w-full justify-between">
|
|
|
|
- <div class=" self-center text-xs font-medium">{$i18n.t('Text-to-Speech 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={TTSEngine}
|
|
|
|
- placeholder="Select a mode"
|
|
|
|
- on:change={(e) => {
|
|
|
|
- if (e.target.value === 'openai') {
|
|
|
|
- getOpenAIVoices();
|
|
|
|
- OpenAISpeaker = 'alloy';
|
|
|
|
- model = 'tts-1';
|
|
|
|
- } else {
|
|
|
|
- getWebAPIVoices();
|
|
|
|
- speaker = '';
|
|
|
|
- }
|
|
|
|
- }}
|
|
|
|
- >
|
|
|
|
- <option value="">{$i18n.t('Default (Web API)')}</option>
|
|
|
|
- <option value="openai">{$i18n.t('Open AI')}</option>
|
|
|
|
- </select>
|
|
|
|
- </div>
|
|
|
|
- </div>
|
|
|
|
-
|
|
|
|
- {#if $user.role === 'admin'}
|
|
|
|
- {#if TTSEngine === 'openai'}
|
|
|
|
- <div class="mt-1 flex gap-2 mb-1">
|
|
|
|
- <input
|
|
|
|
- class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
|
|
|
|
- placeholder={$i18n.t('API Base URL')}
|
|
|
|
- bind:value={OpenAIUrl}
|
|
|
|
- required
|
|
|
|
- />
|
|
|
|
-
|
|
|
|
- <input
|
|
|
|
- class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
|
|
|
|
- placeholder={$i18n.t('API Key')}
|
|
|
|
- bind:value={OpenAIKey}
|
|
|
|
- required
|
|
|
|
- />
|
|
|
|
- </div>
|
|
|
|
- {/if}
|
|
|
|
- {/if}
|
|
|
|
-
|
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Auto-playback response')}</div>
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Auto-playback response')}</div>
|
|
|
|
|
|
@@ -277,21 +151,21 @@
|
|
|
|
|
|
<hr class=" dark:border-gray-700" />
|
|
<hr class=" dark:border-gray-700" />
|
|
|
|
|
|
- {#if TTSEngine === ''}
|
|
|
|
|
|
+ {#if $config.audio.tts.engine === ''}
|
|
<div>
|
|
<div>
|
|
<div class=" mb-2.5 text-sm font-medium">{$i18n.t('Set Voice')}</div>
|
|
<div class=" mb-2.5 text-sm font-medium">{$i18n.t('Set Voice')}</div>
|
|
<div class="flex w-full">
|
|
<div class="flex w-full">
|
|
<div class="flex-1">
|
|
<div class="flex-1">
|
|
<select
|
|
<select
|
|
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
|
|
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
|
|
- bind:value={speaker}
|
|
|
|
|
|
+ bind:value={voice}
|
|
>
|
|
>
|
|
- <option value="" selected={speaker !== ''}>{$i18n.t('Default')}</option>
|
|
|
|
- {#each voices.filter((v) => nonLocalVoices || v.localService === true) as voice}
|
|
|
|
|
|
+ <option value="" selected={voice !== ''}>{$i18n.t('Default')}</option>
|
|
|
|
+ {#each voices.filter((v) => nonLocalVoices || v.localService === true) as _voice}
|
|
<option
|
|
<option
|
|
- value={voice.name}
|
|
|
|
|
|
+ value={_voice.name}
|
|
class="bg-gray-100 dark:bg-gray-700"
|
|
class="bg-gray-100 dark:bg-gray-700"
|
|
- selected={speaker === voice.name}>{voice.name}</option
|
|
|
|
|
|
+ selected={voice === _voice.name}>{_voice.name}</option
|
|
>
|
|
>
|
|
{/each}
|
|
{/each}
|
|
</select>
|
|
</select>
|
|
@@ -307,7 +181,7 @@
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
- {:else if TTSEngine === 'openai'}
|
|
|
|
|
|
+ {:else if $config.audio.tts.engine === 'openai'}
|
|
<div>
|
|
<div>
|
|
<div class=" mb-2.5 text-sm font-medium">{$i18n.t('Set Voice')}</div>
|
|
<div class=" mb-2.5 text-sm font-medium">{$i18n.t('Set Voice')}</div>
|
|
<div class="flex w-full">
|
|
<div class="flex w-full">
|
|
@@ -315,7 +189,7 @@
|
|
<input
|
|
<input
|
|
list="voice-list"
|
|
list="voice-list"
|
|
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
|
|
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
|
|
- bind:value={OpenAISpeaker}
|
|
|
|
|
|
+ bind:value={voice}
|
|
placeholder="Select a voice"
|
|
placeholder="Select a voice"
|
|
/>
|
|
/>
|
|
|
|
|
|
@@ -327,25 +201,6 @@
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
- <div>
|
|
|
|
- <div class=" mb-2.5 text-sm font-medium">{$i18n.t('Set Model')}</div>
|
|
|
|
- <div class="flex w-full">
|
|
|
|
- <div class="flex-1">
|
|
|
|
- <input
|
|
|
|
- list="model-list"
|
|
|
|
- class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
|
|
|
|
- bind:value={model}
|
|
|
|
- placeholder="Select a model"
|
|
|
|
- />
|
|
|
|
-
|
|
|
|
- <datalist id="model-list">
|
|
|
|
- {#each models as model}
|
|
|
|
- <option value={model.name} />
|
|
|
|
- {/each}
|
|
|
|
- </datalist>
|
|
|
|
- </div>
|
|
|
|
- </div>
|
|
|
|
- </div>
|
|
|
|
{/if}
|
|
{/if}
|
|
</div>
|
|
</div>
|
|
|
|
|