2024-02-06 05:05:38 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { createEventDispatcher, onMount } from 'svelte';
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
|
|
export let saveSettings: Function;
|
|
|
|
|
|
|
|
|
|
// Voice
|
2024-02-06 05:36:03 +00:00
|
|
|
let engines = ['', 'openai'];
|
|
|
|
|
let selectedEngine = '';
|
|
|
|
|
|
|
|
|
|
let voices = [];
|
|
|
|
|
let speaker = '';
|
2024-02-06 05:05:38 +00:00
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');
|
|
|
|
|
|
2024-02-06 05:36:03 +00:00
|
|
|
speaker = settings.speaker ?? '';
|
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);
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<form
|
|
|
|
|
class="flex flex-col h-full justify-between space-y-3 text-sm"
|
|
|
|
|
on:submit|preventDefault={() => {
|
|
|
|
|
saveSettings({
|
2024-02-06 05:36:03 +00:00
|
|
|
speaker: speaker !== '' ? speaker : undefined
|
2024-02-06 05:05:38 +00:00
|
|
|
});
|
|
|
|
|
dispatch('save');
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<div class=" space-y-3">
|
2024-02-06 05:36:03 +00:00
|
|
|
<div class=" py-0.5 flex w-full justify-between">
|
|
|
|
|
<div class=" self-center text-sm font-medium">Speech Engine</div>
|
|
|
|
|
<div class="flex items-center relative">
|
|
|
|
|
<select
|
|
|
|
|
class="w-fit pr-8 rounded py-2 px-2 text-xs bg-transparent outline-none text-right"
|
|
|
|
|
bind:value={selectedEngine}
|
|
|
|
|
placeholder="Select a mode"
|
|
|
|
|
on:change={(e) => {
|
|
|
|
|
console.log(e);
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<option value="">Default (Web API)</option>
|
|
|
|
|
<option value="openai">Open AI</option>
|
|
|
|
|
</select>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<hr class=" dark:border-gray-700" />
|
|
|
|
|
|
|
|
|
|
{#if selectedEngine === ''}
|
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-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>
|