Voice.svelte 2.5 KB
Newer Older
Timothy J. Baek's avatar
Timothy J. Baek committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<script lang="ts">
	import { createEventDispatcher, onMount } from 'svelte';
	import { voices } from '$lib/stores';
	const dispatch = createEventDispatcher();

	export let saveSettings: Function;

	// Voice
	let speakVoice = '';

	onMount(async () => {
		let settings = JSON.parse(localStorage.getItem('settings') ?? '{}');

		speakVoice = settings.speakVoice ?? '';

		const getVoicesLoop = setInterval(async () => {
			const _voices = await speechSynthesis.getVoices();
			await voices.set(_voices);

			// do your loop
			if (_voices.length > 0) {
				clearInterval(getVoicesLoop);
			}
		}, 100);
	});
</script>

<form
	class="flex flex-col h-full justify-between space-y-3 text-sm"
	on:submit|preventDefault={() => {
		saveSettings({
			speakVoice: speakVoice !== '' ? speakVoice : undefined
		});
		dispatch('save');
	}}
>
	<div class=" space-y-3">
		<div class=" space-y-3">
			<div>
				<div class=" mb-2.5 text-sm font-medium">Set Default 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={speakVoice}
							placeholder="Select a voice"
						>
							<option value="" selected>Default</option>
							{#each $voices.filter((v) => v.localService === true) as voice}
								<option value={voice.name} class="bg-gray-100 dark:bg-gray-700">{voice.name}</option
								>
							{/each}
						</select>
					</div>
				</div>
			</div>
		</div>

		<!--
							<div>
								<div class=" mb-2.5 text-sm font-medium">
									Gravatar Email <span class=" text-gray-400 text-sm">(optional)</span>
								</div>
								<div class="flex w-full">
									<div class="flex-1">
										<input
											class="w-full rounded py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-800 outline-none"
											placeholder="Enter Your Email"
											bind:value={gravatarEmail}
											autocomplete="off"
											type="email"
										/>
									</div>
								</div>
								<div class="mt-2 text-xs text-gray-400 dark:text-gray-500">
									Changes user profile image to match your <a
										class=" text-gray-500 dark:text-gray-300 font-medium"
										href="https://gravatar.com/"
										target="_blank">Gravatar.</a
									>
								</div>
							</div> -->
	</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>