"use client"; import axios from "axios"; import * as React from 'react'; import { Check, ChevronsUpDown } from "lucide-react" import { useEffect, useState } from "react"; import { useSession } from "next-auth/react"; import { cn } from "@/lib/utils"; import { Skeleton } from "@/components/ui/skeleton"; import { Button } from "@/components/ui/button" import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem } from "@/components/ui/command" import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" import { Label } from "@/components/ui/label"; import { Checkbox } from "@/components/ui/checkbox"; import voices from "@/data/tts"; const TTSVoiceFiltersPage = () => { const { data: session, status } = useSession(); const [loading, setLoading] = useState(true) const [open, setOpen] = useState(false) const [value, setValue] = useState(0) const [enabled, setEnabled] = useState(0) useEffect(() => { axios.get("/api/settings/tts/default") .then((voice) => { setValue(Number.parseInt(voice.data.value)) }) axios.get("/api/settings/tts") .then((d) => { const total = d.data.reduce((acc: number, item: {value: number, label: string, gender: string, language: string}) => acc |= 1 << (item.value - 1), 0) setEnabled(total) }) }, []) const onDefaultChange = (voice: string) => { try { axios.post("/api/settings/tts/default", { voice }) .then(d => { console.log(d) }) .catch(e => console.error(e)) } catch (error) { console.log("[TTS/DEFAULT]", error); return; } } const onEnabledChanged = (val: number) => { try { axios.post("/api/settings/tts", { voice: val }) .then(d => { console.log(d) }) .catch(e => console.error(e)) } catch (error) { console.log("[TTS]", error); return; } } return (
TTS Voices
Default Voice
No voices found. {voices.map((voice) => ( { setValue(Number.parseInt(currentValue)) onDefaultChange(voice.label) setOpen(false) }} > {voice.label} ))}

Voices Enabled

{voices.map((v, i) => (
{ const newVal = enabled ^ (1 << (Number.parseInt(v.value) - 1)) setEnabled(newVal) onEnabledChanged(newVal) }} checked={(enabled & (1 << (Number.parseInt(v.value) - 1))) > 0} />
{v.label}
))}
); } export default TTSVoiceFiltersPage;