Skip to content

Commit c3d5c59

Browse files
committed
Add validation for voice generation chunks and error handling for empty waveforms
1 parent 18cf458 commit c3d5c59

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/lib/shared/kokoro/kokoro.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export async function generateVoice(params: {
7979
}
8080

8181
if (chunk.type === "text") {
82+
if (chunk.tokens?.length ?? 0 < 1) {
83+
console.log("Skipping chunk with no tokens");
84+
continue;
85+
}
86+
8287
console.log({ type: chunk.type, content: chunk.content });
8388

8489
const tokens = chunk.tokens;
@@ -103,6 +108,10 @@ export async function generateVoice(params: {
103108
}
104109
}
105110

111+
if (waveforms.length === 0) {
112+
throw new Error("No waveforms generated");
113+
}
114+
106115
const finalWaveform = new Float32Array(waveformsLen);
107116
let offset = 0;
108117
for (const waveform of waveforms) {

0 commit comments

Comments
 (0)