diff --git a/packages/api/src/routers/article_router.ts b/packages/api/src/routers/article_router.ts index 85ccf9b0a..e9f851286 100644 --- a/packages/api/src/routers/article_router.ts +++ b/packages/api/src/routers/article_router.ts @@ -120,7 +120,7 @@ export function articleRouter() { return res.status(200).send('Page not found') } - const text = parseHTML(page.content).document.documentElement.textContent + const text = parseHTML(page.content).document.documentElement.innerText if (!text) { return res.status(200).send('Page has no text') } diff --git a/packages/api/src/utils/textToSpeech.ts b/packages/api/src/utils/textToSpeech.ts index 7f1a1d45c..b8249c14e 100644 --- a/packages/api/src/utils/textToSpeech.ts +++ b/packages/api/src/utils/textToSpeech.ts @@ -129,13 +129,19 @@ export const synthesizeTextToSpeech = async ( ) }) } - // slice the text into chunks of 1,000 characters - const textChunks = input.text.match(/(.|[\r\n]){1,1000}/g) || [] + // slice the text into chunks of 5,000 characters + let currentTextChunk = '' + const textChunks = input.text.split('\n') for (const textChunk of textChunks) { - logger.debug(`synthesizing ${textChunk}`) - const result = await speakTextAsyncPromise(textChunk) + currentTextChunk += textChunk + '\n' + if (currentTextChunk.length < 5000) { + continue + } + logger.debug(`synthesizing ${currentTextChunk}`) + const result = await speakTextAsyncPromise(currentTextChunk) timeOffset = timeOffset + result.audioDuration - characterOffset = characterOffset + textChunk.length + characterOffset = characterOffset + currentTextChunk.length + currentTextChunk = '' } writeStream.end() synthesizer.close()