we do it live

This commit is contained in:
Jack Merrill 2025-05-05 17:05:42 -04:00
parent abde158e34
commit 1f0f09d254
Signed by: jack
GPG Key ID: F6BFCA1B80EA6AF7
3 changed files with 20 additions and 8 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -10,6 +10,7 @@ import React, {
} from "react";
import removeMarkdown from "remove-markdown";
import { toast } from "sonner";
import * as Echogarden from "echogarden";
// More robust sentence splitter using Intl.Segmenter for better accuracy.
function splitIntoSentences(text: string): string[] {
@ -64,18 +65,28 @@ export const TTSProvider = ({
async function generateTTS(sentence: string, index: number): Promise<string> {
try {
const { data, error } = await supabase.functions.invoke("generate-tts", {
body: {
text: sentence,
voice: selectedSpeaker,
index,
},
// const { data, error } = await supabase.functions.invoke("generate-tts", {
// body: {
// text: sentence,
// voice: selectedSpeaker,
// index,
// },
// });
const { audio } = await Echogarden.synthesize(sentence, {
engine: "kokoro",
voice: selectedSpeaker,
});
setStatus("running");
const { audioUrl } = data as { audioUrl: string };
return audioUrl;
if (!Buffer.isBuffer(audio)) {
throw new Error("Audio data is not a buffer");
}
const blob = new Blob([audio], { type: "audio/wav" });
return URL.createObjectURL(blob);
} catch (error) {
console.error("Error generating TTS:", error);
toast.error("Failed to generate TTS. Please try again.");

View File

@ -28,6 +28,7 @@
"autoprefixer": "10.4.20",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"echogarden": "^2.7.0",
"kokoro-js": "^1.2.0",
"lucide-react": "^0.486.0",
"next": "latest",