2023-12-31 05:41:55 -05:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import axios from "axios";
|
|
|
|
import * as React from 'react';
|
|
|
|
import { Check, ChevronsUpDown } from "lucide-react"
|
2024-06-24 18:16:55 -04:00
|
|
|
import { useEffect, useReducer, useState } from "react";
|
2023-12-31 05:41:55 -05:00
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
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";
|
2024-01-04 02:14:11 -05:00
|
|
|
import { Checkbox } from "@/components/ui/checkbox";
|
|
|
|
import voices from "@/data/tts";
|
2024-01-06 15:17:04 -05:00
|
|
|
import InfoNotice from "@/components/elements/info-notice";
|
2023-12-31 05:41:55 -05:00
|
|
|
|
2024-01-04 16:57:32 -05:00
|
|
|
const TTSVoiceFiltersPage = () => {
|
2023-12-31 05:41:55 -05:00
|
|
|
const [open, setOpen] = useState(false)
|
2024-06-24 18:16:55 -04:00
|
|
|
const [defaultVoice, setDefaultVoice] = useState("")
|
|
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
|
|
|
|
function enabledVoicesReducer(enabledVoices: { [voice: string]: boolean }, action: { type: string, value: string }) {
|
|
|
|
if (action.type == "enable") {
|
|
|
|
return { ...enabledVoices, [action.value]: true }
|
|
|
|
} else if (action.type == "disable") {
|
|
|
|
return { ...enabledVoices, [action.value]: false }
|
|
|
|
}
|
|
|
|
return enabledVoices
|
|
|
|
}
|
|
|
|
|
|
|
|
const [enabledVoices, dispatchEnabledVoices] = useReducer(enabledVoicesReducer, Object.assign({}, ...voices.map(v => ({[v]: false}) )))
|
2023-12-31 05:41:55 -05:00
|
|
|
|
2024-01-04 02:14:11 -05:00
|
|
|
useEffect(() => {
|
|
|
|
axios.get("/api/settings/tts/default")
|
|
|
|
.then((voice) => {
|
2024-06-24 18:16:55 -04:00
|
|
|
setDefaultVoice(voice.data)
|
2024-01-04 02:14:11 -05:00
|
|
|
})
|
2024-06-24 18:16:55 -04:00
|
|
|
|
2024-01-04 02:14:11 -05:00
|
|
|
axios.get("/api/settings/tts")
|
|
|
|
.then((d) => {
|
2024-06-24 18:16:55 -04:00
|
|
|
const data: string[] = d.data;
|
|
|
|
data.forEach(d => dispatchEnabledVoices({ type: "enable", value: d }))
|
|
|
|
setLoading(false)
|
2024-01-04 02:14:11 -05:00
|
|
|
})
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
const onDefaultChange = (voice: string) => {
|
|
|
|
try {
|
|
|
|
axios.post("/api/settings/tts/default", { voice })
|
|
|
|
.catch(e => console.error(e))
|
|
|
|
} catch (error) {
|
|
|
|
console.log("[TTS/DEFAULT]", error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-24 18:16:55 -04:00
|
|
|
const onEnabledChanged = (voice: string, state: boolean) => {
|
2024-01-04 02:14:11 -05:00
|
|
|
try {
|
2024-06-24 18:16:55 -04:00
|
|
|
axios.post("/api/settings/tts", { voice: voice, state: state })
|
2024-01-04 02:14:11 -05:00
|
|
|
.catch(e => console.error(e))
|
|
|
|
} catch (error) {
|
2024-06-24 18:16:55 -04:00
|
|
|
console.log("[TTS/ENABLED]", error);
|
2024-01-04 02:14:11 -05:00
|
|
|
}
|
|
|
|
}
|
2023-12-31 05:41:55 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div className="text-2xl text-center pt-[50px]">TTS Voices</div>
|
2024-01-04 02:14:11 -05:00
|
|
|
<div className="px-10 py-10 w-full h-full flex-grow">
|
|
|
|
<div className="flex flex-row justify-evenly">
|
|
|
|
<div>
|
|
|
|
<div className="inline-block text-lg">Default Voice</div>
|
|
|
|
<Label className="pl-[10px] inline-block">Voice used without any voice modifiers</Label>
|
|
|
|
</div>
|
2023-12-31 05:41:55 -05:00
|
|
|
<Popover open={open} onOpenChange={setOpen}>
|
|
|
|
<PopoverTrigger asChild>
|
|
|
|
<Button
|
|
|
|
variant="outline"
|
|
|
|
role="combobox"
|
|
|
|
aria-expanded={open}
|
2024-01-04 02:14:11 -05:00
|
|
|
className="w-[200px] justify-between">
|
2024-06-24 18:16:55 -04:00
|
|
|
{defaultVoice ? voices.find(v => v == defaultVoice) : "Select voice..."}
|
2023-12-31 05:41:55 -05:00
|
|
|
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
|
|
|
</Button>
|
|
|
|
</PopoverTrigger>
|
|
|
|
<PopoverContent className="w-[200px] p-0">
|
|
|
|
<Command>
|
|
|
|
<CommandInput placeholder="Search voice..." />
|
2024-01-04 02:14:11 -05:00
|
|
|
<CommandEmpty>No voices found.</CommandEmpty>
|
2023-12-31 05:41:55 -05:00
|
|
|
<CommandGroup>
|
|
|
|
{voices.map((voice) => (
|
|
|
|
<CommandItem
|
2024-06-24 18:16:55 -04:00
|
|
|
key={voice}
|
|
|
|
value={voice}
|
|
|
|
onSelect={(currentVoice) => {
|
|
|
|
setDefaultVoice(voice)
|
|
|
|
onDefaultChange(voice)
|
2023-12-31 05:41:55 -05:00
|
|
|
setOpen(false)
|
2024-01-06 15:17:04 -05:00
|
|
|
}}>
|
2023-12-31 05:41:55 -05:00
|
|
|
<Check
|
|
|
|
className={cn(
|
|
|
|
"mr-2 h-4 w-4",
|
2024-06-24 18:16:55 -04:00
|
|
|
defaultVoice === voice ? "opacity-100" : "opacity-0"
|
2023-12-31 05:41:55 -05:00
|
|
|
)}
|
|
|
|
/>
|
2024-06-24 18:16:55 -04:00
|
|
|
{voice}
|
2023-12-31 05:41:55 -05:00
|
|
|
</CommandItem>
|
|
|
|
))}
|
|
|
|
</CommandGroup>
|
|
|
|
</Command>
|
|
|
|
</PopoverContent>
|
|
|
|
</Popover>
|
|
|
|
</div>
|
2024-01-04 02:14:11 -05:00
|
|
|
|
|
|
|
<div className="w-full pt-[50px]">
|
|
|
|
<p className="text-xl text-center justify-center">Voices Enabled</p>
|
2024-01-06 15:17:04 -05:00
|
|
|
<InfoNotice message="Voices can be disabled from being used. Default voice will always work." hidden={false} />
|
2024-01-04 02:14:11 -05:00
|
|
|
<div className="grid grid-cols-4 grid-flow-row gap-4 pt-[20px]">
|
|
|
|
{voices.map((v, i) => (
|
2024-06-24 18:16:55 -04:00
|
|
|
<div key={v + "-enabled"} className="h-[30px] row-span-1 col-span-1 align-middle flex items-center justify-center">
|
2024-01-04 02:14:11 -05:00
|
|
|
<Checkbox onClick={() => {
|
2024-06-24 18:16:55 -04:00
|
|
|
dispatchEnabledVoices({ type: enabledVoices[v] ? "disable" : "enable", value: v })
|
|
|
|
onEnabledChanged(v, !enabledVoices[v])
|
2024-01-04 02:14:11 -05:00
|
|
|
}}
|
2024-06-24 18:16:55 -04:00
|
|
|
disabled={loading}
|
|
|
|
checked={enabledVoices[v]} />
|
|
|
|
<div className="pl-[5px]">{v}</div>
|
2024-01-04 02:14:11 -05:00
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-31 05:41:55 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-01-04 16:57:32 -05:00
|
|
|
export default TTSVoiceFiltersPage;
|