@@ -48,13 +54,13 @@ export default function KokoroReader({ pages }: { pages: any[] }) {
variant="ghost"
size="icon"
className="h-10 w-10"
- onClick={play}
+ onClick={status === "ready" ? play : paused}
disabled={status === null}
>
{status === "running" ? (
) : (
-
Play
+
{playing ? "Pause" : "Play"}
)}
{playing ?
:
}
diff --git a/components/TTSProvider.tsx b/components/TTSProvider.tsx
index 7b85e16..6c2338d 100644
--- a/components/TTSProvider.tsx
+++ b/components/TTSProvider.tsx
@@ -10,7 +10,7 @@ import React, {
} from "react";
import removeMarkdown from "remove-markdown";
import { toast } from "sonner";
-import * as Echogarden from "echogarden";
+import { synthesizeTTSAction } from "@/app/actions";
// More robust sentence splitter using Intl.Segmenter for better accuracy.
function splitIntoSentences(text: string): string[] {
@@ -50,7 +50,6 @@ export const TTSProvider = ({
children: ReactNode;
}) => {
const supabase = createClient();
- // Combine pages and split into sentences.
const fullText = pages.join("\n");
const sentences = splitIntoSentences(fullText).filter(
(sentence) => sentence.trim() !== "\\n" && sentence.trim() !== ""
@@ -63,30 +62,42 @@ export const TTSProvider = ({
const [voices, setVoices] = useState
([]);
const [status, setStatus] = useState<"ready" | "running" | null>("ready");
+ // Cache for preloaded audio
+ const audioCache = useRef