summaryrefslogtreecommitdiff
path: root/src/pages
diff options
context:
space:
mode:
authorpolwex <polwex@sortug.com>2025-06-03 15:41:31 +0700
committerpolwex <polwex@sortug.com>2025-06-03 15:41:31 +0700
commit175ddca375cef765cec8ca5bbc527a205c40bf25 (patch)
treef2e47a5d85e4d5e0297613e5a17cebce7d09b09b /src/pages
parent2401217a4019938d1c1cc61b6e33ccb233eb6e74 (diff)
preeeeettty much done FUCK YES
Diffstat (limited to 'src/pages')
-rw-r--r--src/pages/api/tts.ts81
-rw-r--r--src/pages/tones.tsx6
2 files changed, 84 insertions, 3 deletions
diff --git a/src/pages/api/tts.ts b/src/pages/api/tts.ts
new file mode 100644
index 0000000..bd9a697
--- /dev/null
+++ b/src/pages/api/tts.ts
@@ -0,0 +1,81 @@
+// import db from "../../lib/db";
+import { randomFromArray } from "@/lib/utils";
+import { z } from "zod";
+
+export const GET = async (request: Request): Promise<Response> => {
+ const url = URL.parse(request.url)!;
+ const params = url?.searchParams;
+ const word = params.get("word")!;
+ const lang = params.get("lang")!;
+
+ try {
+ const res = await tts(word, lang);
+ return res;
+ } catch (error) {
+ return Response.json({ message: "Failure" }, { status: 500 });
+ }
+};
+const thaiVoices = [
+ [
+ "s3://voice-cloning-zero-shot/4353be7d-8cd3-4452-9e0b-bc4078c240d7/original/manifest.json",
+ "PlayDialog",
+ ],
+ [
+ "s3://voice-cloning-zero-shot/4c495e1a-1352-4187-99eb-6e5dc7d55059/original/manifest.json",
+ "PlayDialog",
+ ],
+ [
+ "s3://voice-cloning-zero-shot/59933136-5aca-4f42-827f-d354649c62a2/original/manifest.json",
+ "PlayDialog",
+ ],
+ [
+ "s3://voice-cloning-zero-shot/ba9eb1c9-8897-4c41-9c79-f2cb428544a8/original/manifest.json",
+ "PlayDialog",
+ ],
+ [
+ "s3://voice-cloning-zero-shot/bb585812-1c85-4a16-90f7-09c24b6c8186/original/manifest.json",
+ "PlayDialog",
+ ],
+ [
+ "s3://voice-cloning-zero-shot/e1357526-c162-441b-afb9-285d3d21b9b4/original/manifest.json",
+ "PlayDialog",
+ ],
+ [
+ "s3://voice-cloning-zero-shot/edd305a3-9cd2-4dd6-873f-9efc1f73aefc/original/manifest.json",
+ "PlayDialog",
+ ],
+ [
+ "s3://voice-cloning-zero-shot/f80c355d-1075-4d2b-a53d-bb26aa4d1453/original/manifest.json",
+ "PlayDialog",
+ ],
+];
+
+async function tts(text: string, language: string) {
+ const USER_ID = Bun.env.PLAYHT_USER_ID!;
+ const API_KEY = Bun.env.PLAYHT_API_KEY!;
+ const [voice, voice_engine] = randomFromArray(thaiVoices);
+ console.log("tts", text);
+ const url = "https://api.play.ht/api/v2/tts/stream";
+ const options = {
+ method: "POST",
+ headers: {
+ accept: "*/*",
+ "content-type": "application/json",
+ "X-USER-ID": USER_ID,
+ AUTHORIZATION: API_KEY,
+ },
+ body: JSON.stringify({
+ text,
+ voice,
+ // wav, mp3, ogg, flac, mulaw
+ output_format: "wav",
+ quality: "high",
+ voice_engine,
+ language,
+ temperature: 0.7,
+ }),
+ };
+
+ const res = await fetch(url, options);
+ return res;
+}
diff --git a/src/pages/tones.tsx b/src/pages/tones.tsx
index 96ed56c..732ebd1 100644
--- a/src/pages/tones.tsx
+++ b/src/pages/tones.tsx
@@ -12,9 +12,9 @@ export const getConfig = async () => {
// Function to fetch the initial word on the server
async function InitialWordLoader() {
// Fetch a random 1-syllable Thai word with any tone initially
- const initialWord = await fetchWordsByToneAndSyllables(["rising", "mid"]);
- console.log({ initialWord });
- return <ToneSelectorClient initialWord={initialWord} />;
+ const tones = ["falling", "falling"];
+ const initialWords = await fetchWordsByToneAndSyllables(tones);
+ return <ToneSelectorClient initialData={initialWords} initialTones={tones} />;
}
// Loading fallback component