Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hkilang/TTS
Browse files Browse the repository at this point in the history
  • Loading branch information
graphemecluster committed Aug 31, 2024
2 parents af207bf + 8ac5849 commit fdaec64
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
13 changes: 11 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ import type { SettingsDialogPage, Sentence } from "./types";

export default function App() {
const queryOptions = useQueryOptions();
const { language, voice, inferenceMode, voiceSpeed, hakkaToneMode, setLanguage, setVoice } = queryOptions;
const [sentences, setSentences] = useState<Sentence[]>([]);
const { language, voice, inferenceMode, voiceSpeed, hakkaToneMode, setLanguage, setVoice, screenshotMode } = queryOptions;
const [sentences, setSentences] = useState<Sentence[]>(
screenshotMode
? () => [
{ language: "waitau", voice: "male", inferenceMode: "online", voiceSpeed: 1, syllables: segment("天地玄黃,宇宙洪荒。") },
{ language: "waitau", voice: "female", inferenceMode: "online", voiceSpeed: 1, syllables: segment("日月盈昃,辰宿列張。") },
{ language: "hakka", voice: "male", inferenceMode: "online", voiceSpeed: 1, syllables: segment("天地玄黃,宇宙洪荒。") },
{ language: "hakka", voice: "female", inferenceMode: "online", voiceSpeed: 1, syllables: segment("日月盈昃,辰宿列張。") },
]
: [],
);

const textArea = useRef<HTMLTextAreaElement>(null);
const btnAddSentence = useRef<HTMLButtonElement>(null);
Expand Down
12 changes: 9 additions & 3 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ export function useQueryOptions(): QueryOptions {
mode: ALL_INFERENCE_MODES.find(mode => searchParams.has(mode)) || parseOption("mode", ALL_INFERENCE_MODES),
speed: +([searchParams.get("speed"), localStorage.getItem("speed")].find((speed): speed is string => !!speed && +speed >= 0.5 && +speed <= 2) || "1"),
hakka_tones: parseOption("hakka_tones", ALL_HAKKA_TONE_MODES),
screenshot: searchParams.has("screenshot"),
};
});
useEffect(() => {
Object.assign(localStorage, queryOptions);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { screenshot, ...rest } = queryOptions;
Object.assign(localStorage, rest);
}, [queryOptions]);
const { language, voice, mode: inferenceMode, speed: voiceSpeed, hakka_tones: hakkaToneMode } = queryOptions;
const { language, voice, mode: inferenceMode, speed: voiceSpeed, hakka_tones: hakkaToneMode, screenshot: screenshotMode } = queryOptions;
return {
language,
voice,
Expand All @@ -50,8 +53,11 @@ export function useQueryOptions(): QueryOptions {
setInferenceMode: (inferenceMode: InferenceMode) => setQueryOptions(oldOptions => ({ ...oldOptions, mode: inferenceMode })),
setVoiceSpeed: (voiceSpeed: number) => setQueryOptions(oldOptions => ({ ...oldOptions, speed: voiceSpeed })),
setHakkaToneMode: (hakkaToneMode: HakkaToneMode) => setQueryOptions(oldOptions => ({ ...oldOptions, hakka_tones: hakkaToneMode })),
screenshotMode,
get urlWithQuery() {
return `${location.origin}${location.pathname}?${String(new URLSearchParams(queryOptions as unknown as Record<string, string>))}`; // This is fine: number is automatically coalesced to string
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { screenshot, ...rest } = queryOptions;
return `${location.origin}${location.pathname}?${String(new URLSearchParams(rest as unknown as Record<string, string>))}`; // This is fine: number is automatically coalesced to string
},
};
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export interface QueryOptions {
setInferenceMode: Dispatch<InferenceMode>;
setVoiceSpeed: Dispatch<number>;
setHakkaToneMode: Dispatch<HakkaToneMode>;
screenshotMode: boolean;
get urlWithQuery(): string;
}

Expand Down

0 comments on commit fdaec64

Please sign in to comment.