Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/desktop/src/lib/trpc/routers/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,11 @@ export const createSettingsRouter = () => {
Number.isFinite(row.aivisVolume)
? Math.max(0, Math.min(100, row.aivisVolume))
: 100,
speakingRate:
typeof row.aivisSpeakingRate === "number" &&
Number.isFinite(row.aivisSpeakingRate)
? Math.max(0.5, Math.min(2.0, row.aivisSpeakingRate))
: 1.0,
modelPresets: row.aivisModelPresets ?? [],
};
}),
Expand All @@ -1091,6 +1096,7 @@ export const createSettingsRouter = () => {
format: z.string().optional(),
formatPermission: z.string().optional(),
volume: z.number().int().min(0).max(100).optional(),
speakingRate: z.number().min(0.5).max(2.0).optional(),
modelPresets: z
.array(
z.object({
Expand Down Expand Up @@ -1134,6 +1140,10 @@ export const createSettingsRouter = () => {
values.aivisVolume = input.volume;
set.aivisVolume = input.volume;
}
if (input.speakingRate !== undefined) {
values.aivisSpeakingRate = input.speakingRate;
set.aivisSpeakingRate = input.speakingRate;
}
if (input.modelPresets !== undefined) {
values.aivisModelPresets = input.modelPresets;
set.aivisModelPresets = input.modelPresets;
Expand All @@ -1153,6 +1163,7 @@ export const createSettingsRouter = () => {
modelUuid: z.string(),
text: z.string().min(1).max(3000),
userDictionaryUuid: z.string().uuid().optional(),
speakingRate: z.number().min(0.5).max(2.0).optional(),
}),
)
.mutation(async ({ input }) => {
Expand All @@ -1164,6 +1175,7 @@ export const createSettingsRouter = () => {
modelUuid: input.modelUuid,
text: input.text,
userDictionaryUuid: input.userDictionaryUuid,
speakingRate: input.speakingRate,
});
return { success: true };
}),
Expand Down
10 changes: 10 additions & 0 deletions apps/desktop/src/main/lib/notifications/aivis-tts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ function readAivisSettings() {
typeof row?.aivisVolume === "number" && Number.isFinite(row.aivisVolume)
? Math.max(0, Math.min(100, row.aivisVolume))
: 100,
speakingRate:
typeof row?.aivisSpeakingRate === "number" &&
Number.isFinite(row.aivisSpeakingRate)
? Math.max(0.5, Math.min(2.0, row.aivisSpeakingRate))
: 1.0,
};
} catch {
return null;
Expand All @@ -66,13 +71,15 @@ async function synthesize(
modelUuid: string,
text: string,
userDictionaryUuid?: string,
speakingRate?: number,
): Promise<Buffer> {
const body: Record<string, unknown> = {
model_uuid: modelUuid,
text,
output_format: "mp3",
};
if (userDictionaryUuid) body.user_dictionary_uuid = userDictionaryUuid;
if (speakingRate !== undefined) body.speaking_rate = speakingRate;

const res = await fetch(AIVIS_ENDPOINT, {
method: "POST",
Expand Down Expand Up @@ -118,6 +125,7 @@ export async function playAivisTts(options: {
modelUuid: string;
text: string;
volume?: number;
speakingRate?: number;
userDictionaryUuid?: string;
}): Promise<void> {
const trimmed = options.text.trim();
Expand All @@ -131,6 +139,7 @@ export async function playAivisTts(options: {
options.modelUuid,
trimmed,
options.userDictionaryUuid,
options.speakingRate,
);
const path = uniqueTmpPath();
await writeFile(path, audio);
Expand Down Expand Up @@ -162,6 +171,7 @@ export async function playAivisNotification(
modelUuid: cfg.modelUuid,
text,
volume: cfg.volume,
speakingRate: cfg.speakingRate,
userDictionaryUuid: cfg.userDictionaryUuid || undefined,
});
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
SETTING_ITEM_ID,
type SettingItemId,
} from "../../../utils/settings-search";
import { AivisSpeakingRateSlider } from "./components/AivisSpeakingRateSlider";
import { AivisVolumeSlider } from "./components/AivisVolumeSlider";
import { ModelPresetTiles } from "./components/ModelPresetTiles";

Expand Down Expand Up @@ -122,6 +123,7 @@ export function AivisSettings({ visibleItems }: AivisSettingsProps) {
apiKey,
modelUuid,
text: rendered || "テストです",
speakingRate: data?.speakingRate,
});
} catch (err) {
setTestError(err instanceof Error ? err.message : String(err));
Expand Down Expand Up @@ -149,6 +151,7 @@ export function AivisSettings({ visibleItems }: AivisSettingsProps) {
</div>

{enabled && <AivisVolumeSlider disabled={!enabled} />}
{enabled && <AivisSpeakingRateSlider disabled={!enabled} />}

<div className="space-y-2">
<Label htmlFor="aivis-api-key">API Key</Label>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Label } from "@superset/ui/label";
import { Slider } from "@superset/ui/slider";
import { useState } from "react";
import { HiArrowsRightLeft } from "react-icons/hi2";
import { electronTrpc } from "renderer/lib/electron-trpc";

interface Props {
disabled?: boolean;
}

export function AivisSpeakingRateSlider({ disabled }: Props) {
const utils = electronTrpc.useUtils();
const { data } = electronTrpc.settings.getAivisSettings.useQuery();
const save = electronTrpc.settings.setAivisSettings.useMutation({
onSuccess: () => utils.settings.getAivisSettings.invalidate(),
});

const [draft, setDraft] = useState<number | null>(null);

const display = draft ?? data?.speakingRate ?? 1.0;

return (
<div className="space-y-3">
<div className="flex items-center gap-2">
<HiArrowsRightLeft className="h-5 w-5 text-muted-foreground flex-shrink-0" />
<Label htmlFor="aivis-speaking-rate" className="text-sm font-medium">
Speaking Rate
<span className="ml-2 text-xs text-muted-foreground">
{display.toFixed(1)}x
</span>
</Label>
</div>
<Slider
id="aivis-speaking-rate"
value={[display]}
min={0.5}
max={2.0}
step={0.1}
disabled={disabled}
onValueChange={(values) => {
const v = values[0];
if (typeof v !== "number") return;
setDraft(v);
}}
onValueCommit={(values) => {
const v = values[0];
if (typeof v !== "number") return;
setDraft(null);
save.mutate({ speakingRate: v });
}}
/>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AivisSpeakingRateSlider } from "./AivisSpeakingRateSlider";
1 change: 1 addition & 0 deletions packages/local-db/drizzle/0066_add_aivis_speaking_rate.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `settings` ADD `aivis_speaking_rate` real;
Loading
Loading