Skip to content

Commit 009d074

Browse files
committed
chore(tts): halve per-chunk size to 500 chars to reduce cutouts; add TTS chunker test
1 parent 4d7780e commit 009d074

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/main.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,9 @@ function groupSentences(sentences, groupSize = 2) {
850850
}
851851

852852
// Build TTS chunks by character length, prefer ending at sentence boundaries.
853-
// - maxChars: hard cap per chunk (default 1000)
853+
// - maxChars: hard cap per chunk (default 500)
854854
// - If a single sentence exceeds max, split it on whitespace near the limit.
855-
function buildTtsChunks(text, { maxChars = 1000 } = {}) {
855+
function buildTtsChunks(text, { maxChars = 500 } = {}) {
856856
const sents = splitIntoSentences(text);
857857
const chunks = [];
858858
let i = 0;
@@ -947,7 +947,7 @@ function startVoicePlaybackForMessage(message, voice) {
947947
cancelCurrentTtsJob();
948948
const raw = stripNonSpokenParts(message.content || '');
949949
if (!raw) return;
950-
const chunks = buildTtsChunks(raw, { maxChars: 1000 });
950+
const chunks = buildTtsChunks(raw, { maxChars: 500 });
951951
if (!chunks.length) return;
952952

953953
const job = {

tests/tts-chunker.test.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import assert from 'node:assert/strict';
2+
import { readFile } from 'node:fs/promises';
3+
4+
export const name = 'TTS chunker: halved payload (500 char cap) wired in call site';
5+
6+
export async function run() {
7+
const js = await readFile(new URL('../src/main.js', import.meta.url), 'utf8');
8+
const defMatch = js.match(/function\s+buildTtsChunks\s*\(text,\s*\{\s*maxChars\s*=\s*(\d+)\s*\}\s*=\s*\{\}\)\s*\{/);
9+
const defaultMax = defMatch ? Number(defMatch[1]) : null;
10+
assert.equal(defaultMax, 500, 'default maxChars must be 500');
11+
12+
const callMatch = js.match(/buildTtsChunks\(raw,\s*\{\s*maxChars:\s*(\d+)\s*\}\s*\)/);
13+
const callMax = callMatch ? Number(callMatch[1]) : null;
14+
assert.equal(callMax, 500, 'startVoicePlaybackForMessage should request 500-char chunks');
15+
}

0 commit comments

Comments
 (0)