Fix tts preset (#655)

* fix tts preset

* upgrade select ui
This commit is contained in:
an-lee
2024-06-05 10:26:53 +08:00
committed by GitHub
parent cd1a16132a
commit eaba9a960d
2 changed files with 68 additions and 24 deletions

View File

@@ -1,8 +1,13 @@
"use client";
import * as React from "react";
import {
CaretSortIcon,
CheckIcon,
ChevronDownIcon,
ChevronUpIcon,
} from "@radix-ui/react-icons";
import * as SelectPrimitive from "@radix-ui/react-select";
import { Check, ChevronDown } from "lucide-react";
import { cn } from "@renderer/lib/utils";
@@ -19,19 +24,54 @@ const SelectTrigger = React.forwardRef<
<SelectPrimitive.Trigger
ref={ref}
className={cn(
"flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
"flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
className
)}
{...props}
>
{children}
<SelectPrimitive.Icon asChild>
<ChevronDown className="h-4 w-4 opacity-50" />
<CaretSortIcon className="h-4 w-4 opacity-50" />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
));
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName;
const SelectScrollUpButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollUpButton
ref={ref}
className={cn(
"flex cursor-default items-center justify-center py-1",
className
)}
{...props}
>
<ChevronUpIcon />
</SelectPrimitive.ScrollUpButton>
));
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName;
const SelectScrollDownButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollDownButton
ref={ref}
className={cn(
"flex cursor-default items-center justify-center py-1",
className
)}
{...props}
>
<ChevronDownIcon />
</SelectPrimitive.ScrollDownButton>
));
SelectScrollDownButton.displayName =
SelectPrimitive.ScrollDownButton.displayName;
const SelectContent = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
@@ -40,7 +80,7 @@ const SelectContent = React.forwardRef<
<SelectPrimitive.Content
ref={ref}
className={cn(
"relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
"relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
position === "popper" &&
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
className
@@ -48,6 +88,7 @@ const SelectContent = React.forwardRef<
position={position}
{...props}
>
<SelectScrollUpButton />
<SelectPrimitive.Viewport
className={cn(
"p-1",
@@ -57,6 +98,7 @@ const SelectContent = React.forwardRef<
>
{children}
</SelectPrimitive.Viewport>
<SelectScrollDownButton />
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
));
@@ -68,7 +110,7 @@ const SelectLabel = React.forwardRef<
>(({ className, ...props }, ref) => (
<SelectPrimitive.Label
ref={ref}
className={cn("py-1.5 pl-8 pr-2 text-sm font-semibold", className)}
className={cn("px-2 py-1.5 text-sm font-semibold", className)}
{...props}
/>
));
@@ -81,17 +123,16 @@ const SelectItem = React.forwardRef<
<SelectPrimitive.Item
ref={ref}
className={cn(
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
className
)}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
<SelectPrimitive.ItemIndicator>
<Check className="h-4 w-4" />
<CheckIcon className="h-4 w-4" />
</SelectPrimitive.ItemIndicator>
</span>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
));
@@ -118,4 +159,6 @@ export {
SelectLabel,
SelectItem,
SelectSeparator,
SelectScrollUpButton,
SelectScrollDownButton,
};

View File

@@ -49,7 +49,7 @@ export default () => {
type: "tts",
tts: {
engine: currentEngine.name,
model: "tts-1",
model: currentEngine.name === "enjoyai" ? "openai/tts-1" : "tts-1",
voice: "alloy",
},
},
@@ -143,18 +143,19 @@ export default () => {
model: currentEngine.models.default,
tts: {
engine: currentEngine.name,
model: currentEngine.name === "enjoyai" ? "openai/tts-1" : "tts-1",
},
},
};
let defaultTtsPreset = {
key: "tts",
name: "TTS",
engine: "enjoyai",
engine: currentEngine.name,
configuration: {
type: "tts",
tts: {
engine: "enjoyai",
model: "openai/tts-1",
engine: currentEngine.name,
model: currentEngine.name === "enjoyai" ? "openai/tts-1" : "tts-1",
voice: "alloy",
},
},
@@ -166,19 +167,18 @@ export default () => {
const defaultTts = await webApi.config("default_tts_preset");
presets = gptPresets;
defaultGpt.key = "custom";
defaultGpt.name = t("custom");
defaultGpt.engine = currentEngine.name;
defaultGpt.configuration.model = currentEngine.models.default;
defaultGpt.configuration.tts.engine = currentEngine.name;
defaultGptPreset = defaultGpt;
if (defaultGpt.engine === currentEngine.name) {
defaultGpt.key = "custom";
defaultGpt.name = t("custom");
defaultGpt.configuration.model = currentEngine.models.default;
defaultGpt.configuration.tts.engine = currentEngine.name;
if (currentEngine.name === "openai") {
defaultTts.configuration.tts.engine = "openai";
defaultTts.configuration.tts.model = "tts-1";
defaultTts.configuration.tts.voice = "alloy";
defaultGptPreset = defaultGpt;
}
if (defaultTts.engine === currentEngine.name) {
defaultTtsPreset = defaultTts;
}
defaultTtsPreset = defaultTts;
} catch (error) {
console.error(error);
}
@@ -192,6 +192,7 @@ export default () => {
tts: {
...preset.configuration.tts,
engine: currentEngine.name,
model: currentEngine.name === "enjoyai" ? "openai/tts-1" : "tts-1",
},
},
})